/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.*;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.ConvertUpMoneyUtil;
import com.icinfo.cloud.provider.common.utils.DateUtil;
import com.icinfo.cloud.provider.common.utils.HeaderUtil;
import com.icinfo.cloud.provider.peripheralinterface.lawenforce.dto.CaseBaseInfoQueryDto;
import com.icinfo.cloud.provider.peripheralinterface.lawenforce.service.ILawenforceBusinessService;
import com.icinfo.cloud.provider.peripheralinterface.taskcenter.dto.AddTrabeReBaseDto;
import com.icinfo.cloud.provider.peripheralinterface.taskcenter.dto.PunishCooInfoDto;
import com.icinfo.cloud.provider.peripheralinterface.taskcenter.dto.PunishCooInfoRequest;
import com.icinfo.cloud.provider.peripheralinterface.taskcenter.service.ITaskCenterService;
import com.icinfo.cloud.provider.punish.api.dto.FileInfoDto;
import com.icinfo.cloud.provider.punish.approval.dto.AuditDetailDocumentQueryDto;
import com.icinfo.cloud.provider.punish.approval.mapper.CaseApprovalWaitRecordMapper;
import com.icinfo.cloud.provider.punish.approval.model.CaseApprovalWaitRecord;
import com.icinfo.cloud.provider.punish.common.datareport.enums.CaseChangeOperationTypeEnum;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataChangeReportRecordService;
import com.icinfo.cloud.provider.punish.common.documentdataload.dto.CaseDocumentRecordCommonQueryDto;
import com.icinfo.cloud.provider.punish.common.documentoperate.dto.DocumentRelateAttachmentVo;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentLinkObjectTypeEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentRecordStatusEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentStatusEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentTypeEnum;
import com.icinfo.cloud.provider.punish.common.electricsent.enums.DocumentSendStatusEnum;
import com.icinfo.cloud.provider.punish.common.electricsent.mapper.DocumentSendRecordMapper;
import com.icinfo.cloud.provider.punish.common.electricsent.vo.DocumentSendRecordByPartiesVo;
import com.icinfo.cloud.provider.punish.common.sign.vo.DocAttachmentsVo;
import com.icinfo.cloud.provider.punish.config.dto.ConfigDictionaryInfoQueryDto;
import com.icinfo.cloud.provider.punish.config.mapper.ConfigBusiParamDocumentInfoMapper;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.model.SysDepartParam;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.service.IConfigDictionaryInfoService;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.config.vo.ConfigDictionaryInfoVo;
import com.icinfo.cloud.provider.punish.config.vo.MachAssDocumentInfoVo;
import com.icinfo.cloud.provider.punish.config.vo.MachDocumentInfoVo;
import com.icinfo.cloud.provider.punish.csource.manage.dto.CaseSourceLinkRelateDocumentQueryDto;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourceDocumentRecordMapper;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourceMaterialRecordMapper;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourcePartyInfoMapper;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourceRegisterMainInfoMapper;
import com.icinfo.cloud.provider.punish.csource.manage.model.CaseSourceMaterialRecord;
import com.icinfo.cloud.provider.punish.csource.manage.model.CaseSourcePartyInfo;
import com.icinfo.cloud.provider.punish.csource.manage.model.CaseSourceRegisterMainInfo;
import com.icinfo.cloud.provider.punish.csource.manage.service.ICaseSourceDocumentRecordService;
import com.icinfo.cloud.provider.punish.dataprocessing.dto.CaseSearchDto;
import com.icinfo.cloud.provider.punish.fastcase.service.IFastCaseRegisterService;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastAutoCloseCaseReminderVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseButtonVo;
import com.icinfo.cloud.provider.punish.ucase.archive.model.CaseElectricArchiveRecord;
import com.icinfo.cloud.provider.punish.ucase.archive.service.ICaseElectricArchiveRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.*;
import com.icinfo.cloud.provider.punish.ucase.caseregister.dto.CaseEmergencyReasonInfoDto;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.enums.CaseStatusChangeTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.mapper.CaseDocumentAppraisalYjgzsMapper;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.mapper.CaseDocumentAuthedEntrustMapper;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.mapper.CaseDocumentSendinfoConfirmMapper;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.model.CaseDocumentAppraisalYjgzs;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.model.CaseDocumentAuthedEntrust;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.model.CaseDocumentSendinfoConfirm;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.transfer.mapper.CaseTransferRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.transfer.model.CaseTransferRecord;
import com.icinfo.cloud.provider.punish.ucase.payment.enums.PayWayEnum;
import com.icinfo.cloud.provider.punish.ucase.payment.service.ICasePaymentResultRecordService;
import com.icinfo.cloud.provider.punish.ucase.payment.vo.CasePaymentResultRecordVo;
import com.icinfo.cloud.provider.punish.ucase.punishdecide.service.IPunishDecideService;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.service.ICaseDelayInstallmentService;
import com.icinfo.cloud.provider.punish.ucaseassist.assistmain.service.ICaseAssistMainInfoService;
import com.icinfo.cloud.provider.punish.uniquery.dto.UniQueryDto;
import com.icinfo.cloud.provider.punish.uniquery.vo.UniQueryWorkTaskColorsRetVo;
import com.icinfo.cloud.provider.punish.uniquery.vo.UniQueryWorkTaskColorsVo;
import com.icinfo.cloud.provider.punish.uniquery.vo.UniQueryWorkTaskVo;
import com.icinfo.cloud.workflow.config.mapper.ConfigWorkFlowDetailInfoMapper;
import com.icinfo.cloud.workflow.config.model.ConfigWorkFlowDetailInfo;
import com.icinfo.cloud.workflow.config.model.ConfigWorkFlowDocument;
import com.icinfo.cloud.workflow.config.model.ConfigWorkFlowLinkoperateDetailInfo;
import com.icinfo.cloud.workflow.config.service.IConfigWorkFlowDocumentService;
import com.icinfo.cloud.workflow.config.service.IConfigWorkFlowLinkoperateDetailInfoService;
import com.icinfo.cloud.workflow.work.model.WorkFlowRollRecordInfo;
import com.icinfo.cloud.workflow.work.model.WorkFlowRollSubMainInfo;
import com.icinfo.cloud.workflow.work.model.WorkFlowRollSubRecordInfo;
import com.icinfo.cloud.workflow.work.service.IWorkFlowRollMainInfoService;
import com.icinfo.cloud.workflow.work.service.IWorkFlowRollRecordInfoService;
import com.icinfo.cloud.workflow.work.service.IWorkFlowRollSubMainInfoService;
import com.icinfo.cloud.workflow.work.service.IWorkFlowRollSubRecordInfoService;
import com.icinfo.cloud.xzcf.provider.member.org.api.MemberOrgFeignApi;
import com.icinfo.cloud.xzcf.provider.member.org.dto.MemberOrgRequest;
import com.icinfo.cloud.xzcf.provider.member.org.model.MemberOrg;
import com.icinfo.cloud.xzcf.provider.member.role.api.UserRoleFeignApi;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import com.icinfo.framework.tools.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

/**
 * 描述: 案件主表-trj case_main_info 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年02月15日
 */
@Service
@Slf4j
public class CaseMainInfoServiceImpl extends MyBatisServiceSupport implements ICaseMainInfoService {

    /**
     * 可操作的文书隐藏列表
     */
    public static final List<String> OPERATE_HIDE_DOC_LIST;
    /**
     * 关联的文书隐藏列表
     */
    public static final List<String> RELATED_HIDE_DOC_LIST;
    /**
     * 多当事人分别处罚文书隐藏列表
     */
    public static final List<String> MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST;
    /**
     * 阻止操作的案件状态列表
     */
    public static final List<String> PREVENT_DEAL_CASE_STATUS_LIST;
    /**
     * 简案快办可编辑文书种类列表
     */
    public static final List<String> FAST_CASE_ALLOW_EDIT_KIND_CODE_LIST;

    static {
        OPERATE_HIDE_DOC_LIST = new ArrayList<>();
        OPERATE_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_ZXQKHCJL);
        OPERATE_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_SDHZ);

        RELATED_HIDE_DOC_LIST = new ArrayList<>();
        RELATED_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_SDHZ);

        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST = new ArrayList<>();
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_CFGZSPB);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_GZSHZ);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_CFJDSPB);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_BYCFJDSPB);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_DK1BYCFGZSPB);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_CLJDSPB);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_CLGZSPB);
        MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.add(Constant.STRING_KIND_CODE_DK1CSSBFHYJS);

        PREVENT_DEAL_CASE_STATUS_LIST = new ArrayList<>();
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.SUSPEND.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.REVOKE.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.TERMINATE.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.PUNISH_REVOKE.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.HANDLING_CRIMINAL_TRANSFER.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.END_CRIMINAL_TRANSFER.getCode());

        FAST_CASE_ALLOW_EDIT_KIND_CODE_LIST = Arrays.asList(DocumentKindEnum.DOC_KIND_LASPB.getCode(), DocumentKindEnum.DOC_KIND_ZJBG.getCode(),
                DocumentKindEnum.DOC_KIND_CFGZSPB.getCode(), DocumentKindEnum.DOC_KIND_CFGZS.getCode(),
                DocumentKindEnum.DOC_KIND_DK1BYCFGZSPB.getCode(), DocumentKindEnum.DOC_KIND_DK2BYXZCFGZS.getCode());
        PREVENT_DEAL_CASE_STATUS_LIST.add(CaseStatusEnum.TRANSFERRING.getCode());
    }

    @Resource
    ICaseElectricArchiveRecordService caseElectricArchiveRecordService;
    @Resource
    private CaseMainInfoMapper caseMainInfoMapper;
    @Resource
    private ICasePartiesRecordService casePartiesInfoService;
    @Resource
    private IWorkFlowRollRecordInfoService workFlowRollRecordInfoService;
    @Resource
    private IConfigDictionaryInfoService configDictionaryInfoService;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Autowired
    private IConfigWorkFlowDocumentService configWorkFlowDocumentService;
    @Resource
    private ICaseAppendixRecordService caseAppendixRecordService;
    @Resource
    private CaseHandlePersonRecordMapper caseHandlePersonRecordMapper;
    @Resource
    private ICaseReasonMainRecordService caseReasonMainRecordService;
    @Resource
    private ICaseHandlePersonRecordService caseHandlePersonRecordService;
    @Resource
    private CasePartiesLegalInfoMapper casePartiesLegalInfoMapper;
    @Resource
    private ICasePartiesLegalInfoService casePartiesLegalInfoService;
    @Resource
    private ICaseMainInfoStatusChangeRecordService caseMainInfoStatusChangeRecordService;
    @Resource
    private CaseDocumentAppraisalYjgzsMapper caseDocumentAppraisalYjgzsMapper;
    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Resource
    private CasePartiesRecordMapper casePartiesRecordMapper;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Resource
    private CasePartiesPersonInfoMapper casePartiesPersonInfoMapper;
    @Resource
    private CaseDocumentAuthedEntrustMapper caseDocumentAuthedEntrustMapper;
    @Resource
    private CaseDocumentSendinfoConfirmMapper caseDocumentSendinfoConfirmMapper;
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private IWorkFlowRollSubMainInfoService workFlowRollSubMainInfoService;
    @Resource
    private ICaseMainDetailAuxiliaryInfoService caseMainDetailAuxiliaryInfoService;
    @Resource
    private IConfigWorkFlowLinkoperateDetailInfoService configWorkFlowLinkoperateDetailInfoService;
    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
    @Autowired
    private IWorkFlowRollMainInfoService workFlowRollMainInfoService;
    @Resource
    private DocumentSendRecordMapper documentSendRecordMapper;
    @Resource
    private ICasePaymentResultRecordService casePaymentResultRecordService;
    @Resource
    private ICaseMainDetailSimpleInfoService caseMainDetailSimpleInfoService;
    @Resource
    private CaseMainDetailSimpleInfoMapper caseMainDetailSimpleInfoMapper;
    @Resource
    private ICaseRelatedDocumentRecordService caseRelatedDocumentRecordService;
    @Resource
    private ConfigBusiParamDocumentInfoMapper configBusiParamDocumentInfoMapper;
    @Resource
    private IPunishDecideService punishDecideService;
    @Resource
    private ICaseOfflineDocumentRecordService caseOfflineDocumentRecordService;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private CaseInfoAdjustRecordMapper caseInfoAdjustRecordMapper;
    @Autowired
    private IWorkFlowRollSubRecordInfoService workFlowRollSubRecordInfoService;
    @Resource
    private CaseSourceDocumentRecordMapper caseSourceDocumentRecordMapper;
    @Resource
    private CaseSourcePartyInfoMapper caseSourcePartyInfoMapper;
    @Resource
    private CaseSourceRegisterMainInfoMapper caseSourceRegisterMainInfoMapper;
    @Resource
    private CaseSourceMaterialRecordMapper caseSourceMaterialRecordMapper;
    @Resource
    private ICaseSourceDocumentRecordService caseSourceDocumentRecordService;
    @Resource
    private CaseDocumentRecordHisMapper caseDocumentRecordHisMapper;
    @Autowired
    private ICaseAssistMainInfoService caseAssistMainInfoService;
    @Resource
    private ITaskCenterService taskCenterService;
    @Resource
    private ICaseDelayInstallmentService caseDelayInstallmentService;
    @Resource
    private CaseAppendixRecordMapper caseAppendixRecordMapper;
    @Autowired
    private UserRoleFeignApi userRoleFeignApi;
    @Resource
    private CaseTransferRecordMapper caseTransferRecordMapper;
    @Autowired
    private MemberOrgFeignApi memberOrgFeignApi;
    @Resource
    private ILawenforceBusinessService lawenforceBusinessService;
    @Resource
    private ICaseDocumentModifyRecordService caseDocumentModifyRecordService;
    @Resource
    private ICaseDataChangeReportRecordService caseDataChangeReportRecordService;
    @Resource
    private ISysDepartParamService sysDepartParamService;
    @Resource
    private CaseApprovalWaitRecordMapper caseApprovalWaitRecordMapper;
    @Resource
    private ConfigWorkFlowDetailInfoMapper configWorkFlowDetailInfoMapper;
    @Resource
    private IFastCaseRegisterService fastCaseRegisterService;
    @Resource
    private CaseReasonMainRecordMapper caseReasonMainRecordMapper;
    @Value("${member.url}")
    private String memberUrl;

    @Value("${member.api.getAreaListByAreaCode}")
    private String getAreaListByAreaCode;


    @Override
    public CaseDetailInfoVo getCaseDetailInfo(CaseDetailInfoQueryDto queryDto) {
        String caseId = queryDto.getCaseId();
        CaseDetailInfoVo vo = new CaseDetailInfoVo();
        //案件基础信息
        CaseMainInfoVo caseMainInfo = getCaseMainInfo(caseId);
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            throw new BusinessException("未找到案件信息");
        }
        vo.setCaseNumber(caseMainInfo.getCaseNumber());
        vo.setCaseType(caseMainInfo.getCaseType());
        vo.setCaseActsCode(caseMainInfo.getCaseActsCode());
        vo.setCaseQrCodeUrl(caseMainInfo.getCaseQrCodeUrl());
        vo.setCaseBarCodeUrl(caseMainInfo.getCaseBarCodeUrl());
        vo.setCaseExternalActsCode(caseMainInfo.getCaseExternalActsCode());
        vo.setCaseTerritoryCode(caseMainInfo.getCaseTerritoryCode());
        //案件案由、当事人类型
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        if (ObjectUtils.isEmpty(caseMainDetailInfo)) {
            throw new BusinessException("未找到案件信息详情");
        }
        vo.setInvestConclusion(caseMainDetailInfo.getInvestConclusion());
        vo.setHandleConclusion(caseMainDetailInfo.getHandleConclusion());
        vo.setCaseOrgCode(caseMainInfo.getCaseOrgCode());
        vo.setCaseOrgName(caseMainInfo.getCaseOrgName());
        vo.setCaseId(caseId);
        vo.setCaseStatus(caseMainInfo.getCaseStatus());
        vo.setCaseName(caseMainInfo.getCaseName());
        vo.setCaseHappenTime(caseMainDetailInfo.getCaseHappenTime());
        vo.setPunishKinds(caseMainDetailInfo.getPunishKinds());
        vo.setSimpleFormType(caseMainDetailInfo.getSimpleFormType());
        //新增处置方式和案件案由、当事人类型字段
        String handleType = caseMainInfo.getHandleType();
        vo.setHandleType(ObjectUtils.isEmpty(handleType) ? HandleTypeEnum.NORMAL_PUNISH.getCode() : handleType);
        vo.setCasePartiesReasonType(ObjectUtils.isEmpty(casePartiesReasonType) ? PartiesReasonTypeEnum.SINGLE_PARTY.getCode() : casePartiesReasonType);
        //新增是否涉刑移送案件字段
        vo.setIsCriminalTransferCase(caseMainDetailInfo.getHandleConclusion());
        //案发地址
        vo.setCaseHappenAddressDetail(caseMainDetailInfo.getCaseHappenAddressDetail());
        //人社案由
        vo.setPersonReasonName(caseMainDetailInfo.getPersonReasonName());
        //应急案由处理
        vo.setCaseEmergencyReasonContent(caseMainDetailInfo.getCaseEmergencyReasonContent());
        //处罚建议
        vo.setPunishOpinion(caseMainDetailInfo.getPunishOpinion());
        //处罚告知或处罚决定阶段进行是否展示取证按钮判断
        if (CaseStageEnum.PUNISH_INFORM.getCode().equals(caseMainInfo.getCaseCurrentStageCode())
                || CaseStageEnum.PUNISH_DECIDE.getCode().equals(caseMainInfo.getCaseCurrentStageCode())) {
            //是否展示取证按钮(根据陈述申辩复核意见书控制)
            CaseDocumentRecordDto CSSBFHYJSRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode());
            if (ObjectUtil.isNotEmpty(CSSBFHYJSRecord) && DocumentStatusEnum.CHECK_END.getCode().equals(CSSBFHYJSRecord.getDocumentApprovalStatus())) {
                //《陈述申辩复核意见书》审批通过后，展示“在线取证”、“上传线下证据”、“上传线下文书”
                vo.setIsShowEvidenceButton(YesOrNoEnum.YES.getCode());
            }
        }

        //省简案快办自动结案提醒处理
        if (CaseTypeEnum.FAST_PROCEDURE.getCode().equals(caseMainInfo.getCaseType())
                && CaseStageEnum.PUNISH_EXECUTION.getCode().equals(caseMainInfo.getCaseCurrentStageCode())) {
            //只有执行阶段才会触发自动结案提醒
            FastAutoCloseCaseReminderVo autoCloseCaseReminder = fastCaseRegisterService.getAutoCloseCaseReminder(caseId);
            vo.setFastAutoCloseCaseReminderVo(autoCloseCaseReminder);
        }

        //多当事人 分别处罚 调查报告分别返回
        List<Map<String, Object>> investConclusionList = new ArrayList<>();
        if (Constant.STRING_2.equals(handleType)) {
            Example example = new Example(CaseMainDetailAuxiliaryInfo.class);
            example.createCriteria().andEqualTo("caseId", caseId);
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(example);
            for (CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo : caseMainDetailAuxiliaryInfos) {
                Map<String, Object> map = new HashMap<>();
                map.put("partyId", caseMainDetailAuxiliaryInfo.getPartyId());
                map.put("investConclusion", caseMainDetailAuxiliaryInfo.getInvestConclusion());
                investConclusionList.add(map);
            }
        }
        vo.setInvestConclusionList(investConclusionList);
        //获取当事人信息(省略非空判断)
        List<CasePartiesRecordVo> casePartiesInfoList = casePartiesInfoService.getCasePartiesInfo(caseId);
        CasePartiesRecordVo theFirstPartyInfo = casePartiesInfoList.get(Constant.INTEGER_0);
        String partyShowName = theFirstPartyInfo.getPartyName();

        if (PartiesReasonTypeEnum.SINGLE_PARTY.getCode().equals(vo.getCasePartiesReasonType())) {
            vo.setUniscid(theFirstPartyInfo.getPartyIdentityCode());
        }
        int partyNum = casePartiesInfoList.size();
        if (partyNum > 1) {
            partyShowName += "等" + partyNum + "个";
        }
        vo.setPartyShowName(partyShowName);
        //判断是否存在法定代表人证件信息缺失情况
        List<CasePartiesLegalInfoVo> loseLegalCertInfoList = casePartiesLegalInfoService.getLegalInfoWhoLoseLegalCertInfo(caseId);
        String isLoseLegalCertInfoCode = YesOrNoEnum.NO.getCode();
        if (!ObjectUtils.isEmpty(loseLegalCertInfoList) && loseLegalCertInfoList.size() > 0) {
            isLoseLegalCertInfoCode = YesOrNoEnum.YES.getCode();
        }
        vo.setIsLoseLegalCertInfoCode(isLoseLegalCertInfoCode);
        vo.setIsLoseLegalCertInfoName(YesOrNoEnum.getValueByCode(isLoseLegalCertInfoCode));
        //案由  (非人社有案由)
        List<CaseReasonMainRecordVo> caseReasonMainRecordList = caseReasonMainRecordService.getCaseReasonRecordListByCaseId(caseId);
        StringBuilder showCaseReasonName = new StringBuilder();
        StringBuilder showCaseReasonCode = new StringBuilder();
        List<String> illegalBasisFormat = new ArrayList<>();
        List<String> punishBasisFormat = new ArrayList();
        //caseReasonMainRecordList 不会为空，省略非空判断  (人设可能为空调整)
        if (!ObjectUtils.isEmpty(caseReasonMainRecordList) && caseReasonMainRecordList.size() > 0) {
            caseReasonMainRecordList.forEach(e -> {
                showCaseReasonName.append(e.getCaseReasonName() + "；");
                showCaseReasonCode.append(e.getCaseReasonCode() + "；");
                illegalBasisFormat.add(e.getIllegalBasisFormat());
                punishBasisFormat.add(e.getPunishBasisFormat());
            });
            String tmpShowCaseReasonName = showCaseReasonName.toString();
            String tmpShowCaseReasonCode = showCaseReasonCode.toString();
            int endIndex = tmpShowCaseReasonName.length() - 1;
            if (tmpShowCaseReasonName.endsWith("；")) {
                tmpShowCaseReasonName = tmpShowCaseReasonName.substring(0, endIndex);
            }
            if (tmpShowCaseReasonCode.endsWith("；")) {
                endIndex = tmpShowCaseReasonCode.length() - 1;
                tmpShowCaseReasonCode = tmpShowCaseReasonCode.substring(0, endIndex);
            }

            vo.setCaseReasonShowName(tmpShowCaseReasonName);
            vo.setCaseReasonCode(tmpShowCaseReasonCode);
            vo.setIllegalDetailFormat(StringUtils.join(illegalBasisFormat, "，"));
            vo.setPunishDetailFormat(StringUtils.join(punishBasisFormat, "，"));
        }
        //办案人员列表
        List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
        vo.setCaseHandlePersonList(caseHandlePersonRecordList);
        AtomicBoolean isCaseHandlerTemp = new AtomicBoolean(false);
        vo.setIsCaseHandler(YesOrNoEnum.NO.getCode());
        vo.setIsCaseHandlerName(YesOrNoEnum.NO.getDes());
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            throw new BusinessException("登录失效");
        }
        Long userId = userInfo.getUserId();
        if (!ObjectUtils.isEmpty(caseHandlePersonRecordList) && caseHandlePersonRecordList.size() > 0) {
            caseHandlePersonRecordList.forEach(e -> {
                if (HandlePersonTypeEnum.MAIN.getCode().equals(e.getHandlePersonType())
                        && ObjectUtils.isEmpty(vo.getCaseHandlingDeptInfo())) {
                    String caseHandlingDeptInfo = e.getHandleOrgName() + "/" + e.getHandleDeptName();
                    //办案部门
                    vo.setCaseHandlingDeptInfo(caseHandlingDeptInfo);
                }
                if (userId.equals(Long.valueOf(e.getHandlePersonId())) && !isCaseHandlerTemp.get()) {
                    isCaseHandlerTemp.set(true);
                    vo.setIsCaseHandler(YesOrNoEnum.YES.getCode());
                    vo.setIsCaseHandlerName(YesOrNoEnum.YES.getDes());
                }
            });
        }
        vo.setCaseCurrentStageName(caseMainInfo.getCaseCurrentStageName());
        vo.setCaseCurrentStageCode(caseMainInfo.getCaseCurrentStageCode());
        vo.setCaseCurrentLinkName(caseMainInfo.getCaseCurrentLinkName());
        vo.setCaseCurrentLinkCode(caseMainInfo.getCaseCurrentLinkCode());
        /*
            案件总耗时:已结案的展示，结案时间-立案时间；未结案的展示当前时间-立案时间
         */
        LocalDateTime calculateStartTime = caseMainInfo.getCaseRegistTime();
        if (!ObjectUtils.isEmpty(calculateStartTime)) {
            LocalDateTime calculateEndTime = caseMainInfo.getCaseEndTime();
            if (ObjectUtils.isEmpty(calculateEndTime)) {
                calculateEndTime = LocalDateTime.now();
            }
            HashMap<String, String> map = DateUtil.calculateTimeIntervalInfo(calculateStartTime, calculateEndTime, false);
            String caseTotalTime = map.get("showTime");
            vo.setCaseTotalTime(caseTotalTime);
        }

        /*
        立案日期到办案期限；决定书送达前，展示当日距办案期限的天数，若在办案期限前的，
        展示剩N天，在办案期限后的，展示超N天，其中N=当日-办案期限；若当日同办案期限，展示“已到期”；
         */
        if (!ObjectUtils.isEmpty(calculateStartTime)) {
            LocalDate caseHandleStartDate = calculateStartTime.toLocalDate();
            vo.setCaseHandleStartDate(caseHandleStartDate);
            LocalDateTime caseTimeLimit = caseMainInfo.getCaseTimelimit();
            if (!ObjectUtils.isEmpty(caseTimeLimit)) {
                LocalDate caseHandleDeadlineEndDate = caseTimeLimit.toLocalDate();
                //鉴定 中止与恢复 办案期限计算
                CaseMainInfoStatusChangeRecord record = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(vo.getCaseId(), CaseStatusChangeTypeEnum.SUSPEND.getCode());
                if (null != record) {
                    //暂停，则原有的办案期限+（当前日期-中止日期）
                    if (Constant.STRING_1.equals(record.getStatus())) {
                        long days = DateUtil.calculatePastDays(record.getChangeEffectTime().toLocalDate());
                        caseHandleDeadlineEndDate = caseTimeLimit.plusDays(days).toLocalDate();
                    }
                }
                vo.setCaseHandleDeadlineEndDate(caseHandleDeadlineEndDate);

                LocalDateTime caseVerdictEndTime = caseMainInfo.getCaseVerdictEndTime();
                //裁决完毕，组装裁决期限状态描述
                if (!ObjectUtils.isEmpty(caseVerdictEndTime)) {
                    vo.setCaseVerdictEndTime(caseVerdictEndTime.toLocalDate());

                    long count = caseHandleDeadlineEndDate.toEpochDay() - caseVerdictEndTime.toLocalDate().toEpochDay();
                    //裁决完毕超期，添加状态描述
                    if (count < 0) {
                        Map<String, String> verdictEndTimeStatusMap
                                = assembleCaseHandleDeadlineStatusInfo(caseVerdictEndTime.toLocalDate(), caseHandleDeadlineEndDate);
                        for (String key : verdictEndTimeStatusMap.keySet()) {
                            String value = verdictEndTimeStatusMap.get(key);
                            vo.setCaseVerdictEndTimeStatus(key);
                            vo.setCaseVerdictEndTimeShowColor(value);
                        }
                    }
                } else {
                    String caseStatus = caseMainInfo.getCaseStatus();
                    //案件立案撤销、终止、涉刑移送结案，不显示期限状态描述
                    if (!(CaseStatusEnum.TERMINATE.getCode().equals(caseStatus) ||
                            CaseStatusEnum.REVOKE.getCode().equals(caseStatus) ||
                            CaseStatusEnum.END_CRIMINAL_TRANSFER.getCode().equals(caseStatus) ||
                            CaseStatusEnum.TRANSFERRING.getCode().equals(caseStatus) ||
                            CaseStatusEnum.END_CASE.getCode().equals(caseStatus))) {
                        //未裁决完毕，组装办案期限状态描述
                        Map<String, String> statusMap = assembleCaseHandleDeadlineStatusInfo(LocalDate.now(), caseHandleDeadlineEndDate);
                        for (String key : statusMap.keySet()) {
                            String value = statusMap.get(key);
                            vo.setCaseHandleDeadlineStatus(key);
                            vo.setCaseHandleDeadlineStatusShowColor(value);
                        }
                    }

                }

            }
        }
        List<CaseDetailStageInfoVo> caseDetailStageInfoList = getCaseDetailStageInfo(caseId);

        vo.setIsCaseOver(YesOrNoEnum.NO.getCode());
        vo.setIsCaseOverName(YesOrNoEnum.NO.getDes());
        if (!ObjectUtils.isEmpty(caseDetailStageInfoList) && caseDetailStageInfoList.size() > 0) {
            CaseDetailStageInfoVo tmp = caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 1);
            if ("stage_end_virtual".equals(tmp.getStageId())) {
                LocalDateTime showTime = tmp.getShowTime();
                if (!ObjectUtils.isEmpty(showTime)) {
                    //已结案
                    vo.setCaseCurrentLinkName("已归档");
                    vo.setCaseCurrentLinkCode("stage_end_virtual");
                    vo.setIsCaseOver(YesOrNoEnum.YES.getCode());
                    vo.setIsCaseOverName(YesOrNoEnum.YES.getDes());
                }

            }
        }
        vo.setCaseStageInfoList(caseDetailStageInfoList);
        //获取案件关联文书
        CaseStageLinkRelateDocumentQueryDto query = new CaseStageLinkRelateDocumentQueryDto();
        query.setCaseId(caseId);

        //根据工作流版本号、工作流编号查询有配对文书目录编码的文书配置信息
        String workFlowVersion = caseMainInfo.getCaseFlowVersion();
        String workFlowCode = caseMainInfo.getCaseFlowCode();
        List<ConfigWorkFlowDocument> list =
                configWorkFlowDocumentService.getConfigWorkFlowDocumentMatchedListByFlowCode(workFlowCode, workFlowVersion);
        Map<String, String> matchMapCataLogCode = new HashMap<>(20);
        Map<String, String> matchMapIsMatchDocument = new HashMap<>(20);
        list.forEach(e -> {
            matchMapCataLogCode.put(e.getDocumentCatalogCode(), e.getMatchedDocumentCatalogCode());
            matchMapIsMatchDocument.put(e.getDocumentCatalogCode(), e.getIsMatchDocument());
        });
        List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList
                = caseDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
        List<CaseStageLinkRelateDocumentVo> caseDetailApprovalTableInfoList = new ArrayList<>();
        List<CaseStageLinkRelateDocumentVo> invalidCaseDetailApprovalTableInfoList = new ArrayList<>();
        List<CaseStageLinkRelateDocumentVo> caseDetailDocInfoList = new ArrayList<>();
        List<CaseStageLinkRelateDocumentVo> invalidCaseDetailDocInfoList = new ArrayList<>();

        //TODO:待优化
        caseStageLinkRelateDocumentList.forEach(e -> {
            String partyId = e.getPartyId();
            String documentCatalogCode = e.getDocumentCatalogCode();
            String kindCode = e.getDocumentKindCode();
            e.setMatchDocumentCatalogCode(matchMapCataLogCode.get(documentCatalogCode));
            e.setIsMatchDocument(matchMapIsMatchDocument.get(documentCatalogCode));
            //根据文书目录编码查询关联文书
            //TODO zheli返回重复了，要改掉后续
            List<String> allRelationDocCatalogCodeList = getALLRelationDocCatalogCodeList(caseMainInfo.getBusiParamId(), documentCatalogCode);
            e.setAllRelationDocCatalogCodeList(allRelationDocCatalogCodeList);
            MachDocumentInfoVo machDocumentInfoVo = getMachDocumentInfo(caseMainInfo.getBusiParamId(), documentCatalogCode);
            e.setMachDocumentInfoVo(machDocumentInfoVo);

            //多当事人案件中，文书中配置关联对象为当事人的，文书列表中标题中增加当事人名称展示。示例：电子送达地址确认书（张三）。
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                    && DocumentLinkObjectTypeEnum.PERSON.getCode().equals(e.getDocumentLinkObjectType())
                    && (!ObjectUtils.isEmpty(partyId) && !partyId.contains(","))) {
                //多当事人合并处罚不拼接当事人名称
                //查询当事人名称
                CasePartiesRecordVo firstPartyInfo = null;
                List<CasePartiesRecordVo> casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
                if (!ObjectUtils.isEmpty(partyId)) {
                    for (CasePartiesRecordVo partiesRecord : casePartiesRecordList) {
                        if (partyId.equals(partiesRecord.getPartyId())) {
                            firstPartyInfo = partiesRecord;
                            break;
                        }
                    }
                } else {
                    firstPartyInfo = casePartiesRecordList.get(Constant.INTEGER_0);
                }
                if (!ObjectUtils.isEmpty(firstPartyInfo)) {
                    e.setDocumentCatalogName(e.getDocumentCatalogName() + "(" + firstPartyInfo.getPartyName() + ")");
                }

            }
            if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(kindCode)) {
                e.setCaseDocumentTypeFlag(Constant.STRING_1);
            }
            //设置文书为有效状态
            e.setIsInvalid("0");

            String documentStatus = e.getDocumentRecordStatus();
            if (DocumentTypeEnum.APPROVAL_TABLE.getCode().equals(e.getDocumentTypeId())) {
                if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(documentStatus)) {
                    //加入作废列表
                    invalidCaseDetailApprovalTableInfoList.add(e);
                } else {
                    caseDetailApprovalTableInfoList.add(e);
                }

            } else {
                if ("JDYJGZS".equals(e.getDocumentKindCode())) {
                    //获取鉴定报告标题加编号
                    Example example = new Example(CaseDocumentAppraisalYjgzs.class);
                    example.createCriteria().andEqualTo("documentId", e.getDocumentId()).andEqualTo("isDeleted", "0");
                    List<CaseDocumentAppraisalYjgzs> caseDocumentAppraisalYjgzsList = caseDocumentAppraisalYjgzsMapper.selectByExample(example);
                    if (null != caseDocumentAppraisalYjgzsList && caseDocumentAppraisalYjgzsList.size() > 0) {
                        CaseDocumentAppraisalYjgzs caseDocumentAppraisalYjgzs = caseDocumentAppraisalYjgzsList.get(0);
                        String reportNum = "";
                        if (StringUtils.isNotBlank(caseDocumentAppraisalYjgzs.getCourierNumber())) {
                            reportNum = caseDocumentAppraisalYjgzs.getCourierNumber();
                        }
                        e.setDocumentCatalogName(e.getDocumentCatalogName() + "(报告名称：" + caseDocumentAppraisalYjgzs.getReportTitle() + "|报告编号：" + reportNum + ")");
                    }
                }

                //设置文书是否有效
                //1.送达方式及地址确认书  从完成确认时间开始计算  有效期一年（365日）
                if (Constant.STRING_KIND_CODE_SDDZQRS.equals(e.getDocumentKindCode())) {
                    Example documentSendinfoConfirm = new Example(CaseDocumentSendinfoConfirm.class);
                    Example.Criteria criteria = documentSendinfoConfirm.createCriteria();
                    criteria.andEqualTo("caseId", caseId)
                            .andEqualTo("status", Constant.INTEGER_0);
                    if (!ObjectUtils.isEmpty(partyId)) {
                        criteria.andEqualTo("partyId", e.getPartyId());
                    }
                    List<CaseDocumentSendinfoConfirm> caseDocumentSendinfoConfirms = caseDocumentSendinfoConfirmMapper.selectByExample(documentSendinfoConfirm);
                    if (!caseDocumentSendinfoConfirms.isEmpty()) {
                        e.setIsInvalid("1");
                    }

                    /*LocalDate localDate = LocalDate.now();
                    //获取确认时间
                    LocalDate confirmDate = e.getDocumentCreateTime().toLocalDate();
                    LocalDate endDate = confirmDate.plusYears(1);
                    if (localDate.isAfter(endDate)) {
                        e.setIsInvalid("1");
                    }*/
                }

                //2.授权委托书      委托期限：到本案终结为止
                if (Constant.STRING_KIND_CODE_SQWTS.equals(kindCode)) {
                    Example documentAuthedEntrust = new Example(CaseDocumentAuthedEntrust.class);
                    documentAuthedEntrust.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", e.getPartyId()).andEqualTo("status", Constant.INTEGER_1);
                    List<CaseDocumentAuthedEntrust> caseDocumentAuthedEntrusts = caseDocumentAuthedEntrustMapper.selectByExample(documentAuthedEntrust);
                    if (caseDocumentAuthedEntrusts.isEmpty()) {
                        e.setIsInvalid("1");
                    }

                    /*if (CaseStatusEnum.END_CASE.getCode().equals(caseMainInfo.getCaseStatus())){
                        e.setIsInvalid("1");
                    }*/
                }
                // 强制执行显示执行情况
                if (DocumentKindEnum.DOC_KIND_QZZXSQS.getCode().equals(kindCode)) {
                    e.setCaseDocumentTypeFlag(Constant.STRING_2);
                }

                //增加处罚决定书是否展示公示详情处理
                if (Constant.STRING_KIND_CODE_CFJDS.equals(kindCode)) {
                    //默认展示公示详情按钮
                    e.setIsShowPublicity(YesOrNoEnum.YES.getCode());
                    e.setIsShowPublicityName("展示公示");
                }

                if (!RELATED_HIDE_DOC_LIST.contains(kindCode)) {
                    if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(documentStatus)) {
                        //加入作废列表
                        invalidCaseDetailDocInfoList.add(e);
                    } else {
                        //增加涉嫌犯罪案件移送记录
                        if (DocumentKindEnum.DOC_KIND_DK2SXFZAJYSS.getCode().equals(e.getDocumentKindCode())
                                && DocumentStatusEnum.CHECK_END.getCode().equals(e.getDocumentApprovalStatus())) {
                            //审批通过才增加移送记录
                            CaseBaseInfoQueryDto caseBaseInfoQueryDto = lawenforceBusinessService.readCaseBaseInfoByCaseId(caseId);
                            if (!ObjectUtils.isEmpty(caseBaseInfoQueryDto)) {
                                CaseStageLinkRelateDocumentVo documentVo = new CaseStageLinkRelateDocumentVo();
                                documentVo.setDocumentId(caseBaseInfoQueryDto.getId());
                                documentVo.setDocumentCatalogName("案件涉刑移送(" + caseBaseInfoQueryDto.getSwdwmc() + ")");
                                documentVo.setCreateUserName(caseBaseInfoQueryDto.getCreateUserName());
                                documentVo.setDocumentCreateTime(e.getApprovalFinishTime());
                                documentVo.setDocumentRecordStatus(DocumentRecordStatusEnum.NORMAL.getCode());
                                documentVo.setLawenforceTransferRecordStatusName(caseBaseInfoQueryDto.getCaseStatusName());
                                //只有详情按钮
                                StringBuilder stringBuilder = new StringBuilder("detail");
                                documentVo.setLawenforceOpButton(stringBuilder.toString());
                                //设置是否修改申请记录
                                documentVo.setIsLawenforceTransferRecord(YesOrNoEnum.YES.getCode());
                                caseDetailApprovalTableInfoList.add(documentVo);
                            }
                        }
                        caseDetailDocInfoList.add(e);
                    }
                }
            }
        });
        //加入关联文书
        List<CaseStageLinkRelateDocumentVo> relatedDocList = caseRelatedDocumentRecordService.getRelatedDocInfoToCaseStageLinkRelateDocument(caseId);
        if (!ObjectUtils.isEmpty(relatedDocList) && relatedDocList.size() > 0) {
            relatedDocList.forEach(e -> {
                String documentType = e.getDocumentTypeId();
                e.setCaseDocumentTypeFlag(Constant.STRING_4);
                if (DocumentTypeEnum.LAW_DOCUMENT.getCode().equals(documentType)) {
                    caseDetailDocInfoList.add(e);
                } else if (DocumentTypeEnum.APPROVAL_TABLE.getCode().equals(documentType)) {
                    caseDetailApprovalTableInfoList.add(e);
                }
            });
        }
        //加入线下上传文书
        List<CaseStageLinkRelateDocumentVo> offlineDocList = caseOfflineDocumentRecordService.getOfflineDocInfoToCaseStageLinkRelateDocument(caseId);
        if (!ObjectUtils.isEmpty(offlineDocList) && offlineDocList.size() > 0) {
            offlineDocList.forEach(e -> {
                String documentType = e.getDocumentTypeId();
                e.setCaseDocumentTypeFlag(Constant.STRING_3);
                if (DocumentTypeEnum.LAW_DOCUMENT.getCode().equals(documentType)) {
                    caseDetailDocInfoList.add(e);
                } else if (DocumentTypeEnum.APPROVAL_TABLE.getCode().equals(documentType)) {
                    caseDetailApprovalTableInfoList.add(e);
                }
            });
        }

        vo.setCaseDetailApprovalTableInfoList(caseDetailApprovalTableInfoList);
        vo.setCaseDetailDocInfoList(caseDetailDocInfoList);

        vo.setInvalidCaseDetailApprovalTableInfoList(invalidCaseDetailApprovalTableInfoList);
        vo.setInvalidCaseDetailDocInfoList(invalidCaseDetailDocInfoList);

        CaseKeyInfoQueryDto queryOperateDoc = new CaseKeyInfoQueryDto();
        queryOperateDoc.setDocumentTypeName(DocumentTypeEnum.APPROVAL_TABLE.getCode());
        queryOperateDoc.setCaseMainInfo(caseMainInfo);

        String caseStatus = caseMainInfo.getCaseStatus();
        if (validateCaseIsInNotDealStatus(caseMainInfo, null) && !CaseStatusEnum.SUSPEND.getCode().equals(caseStatus)) {
            vo.setCaseDetailOperateApprovalTableInfoVoList(null);
            vo.setCaseDetailOperateDocInfoVoList(null);
        } else if ((Constant.STRING_3.equals(caseMainInfo.getCaseType()) || CaseTypeEnum.FAST_PROCEDURE.getCode().equals(caseMainInfo.getCaseType()))
                && StringUtils.isBlank(caseMainInfo.getCaseNumber())) {
            //安吉速结或简案快办 未立案成功 则无需展示文书制作
            vo.setCaseDetailOperateApprovalTableInfoVoList(null);
            vo.setCaseDetailOperateDocInfoVoList(null);
        } else {
            vo.setCaseDetailOperateApprovalTableInfoVoList(getCouldBeOperateDocListCurrentStage(queryOperateDoc));
            queryOperateDoc.setDocumentTypeName(DocumentTypeEnum.LAW_DOCUMENT.getCode());
            queryOperateDoc.setIsMobile(queryDto.getIsMobile());
            vo.setCaseDetailOperateDocInfoVoList(getCouldBeOperateDocListCurrentStage(queryOperateDoc));
        }

        CaseAttachmentInfoQueryDto attachmentInfoQueryDto = new CaseAttachmentInfoQueryDto();
        attachmentInfoQueryDto.setCaseId(caseId);
        attachmentInfoQueryDto.setIsExcludeDocument(YesOrNoEnum.YES.getCode());
        List<CaseAttachmentInfoVo> caseAttachmentInfoList = caseAppendixRecordService.getCaseAttachmentList(attachmentInfoQueryDto);
        List<CaseDetailOtherMaterialInfoVo> caseDetailOtherMaterialInfoList = new ArrayList<>();
        List<CaseDetailOtherMaterialInfoVo> invalidCaseDetailOtherMaterialInfoList = new ArrayList<>();
        caseAttachmentInfoList.forEach(e -> {
            CaseDetailOtherMaterialInfoVo caseDetailOtherMaterialInfo = new CaseDetailOtherMaterialInfoVo();
            caseDetailOtherMaterialInfo.setFileUrl(e.getAppendixUrl());
            caseDetailOtherMaterialInfo.setFileName(e.getAppendixName());
            caseDetailOtherMaterialInfo.setCreateTime(e.getUploadTime());
            caseDetailOtherMaterialInfo.setCreateUserName(e.getUploadUserName());
            String appendixStatus = e.getAppendixStatus();
            if (Constant.STRING_3.equals(appendixStatus)) {
                //加入作废列表
                invalidCaseDetailOtherMaterialInfoList.add(caseDetailOtherMaterialInfo);
            } else {
                caseDetailOtherMaterialInfoList.add(caseDetailOtherMaterialInfo);
            }
        });
        vo.setCaseDetailOtherMaterialInfoList(caseDetailOtherMaterialInfoList);
        vo.setInvalidCaseDetailOtherMaterialInfoList(invalidCaseDetailOtherMaterialInfoList);
        String isShowPartiesSelector = validateIsShowPartiesSelector(caseMainInfo, null);
        vo.setIsShowPartiesSelector(isShowPartiesSelector);
        vo.setIsShowPartiesSelectorName(YesOrNoEnum.getValueByCode(isShowPartiesSelector));
        if (validateIsNeedPassPartyId(caseMainInfo, null)) {
            List<PartiesSubFlowInfoVo> partiesSubFlowInfo = getPartiesSubFlowInfo(caseId);
            vo.setPartiesSubFlowInfo(partiesSubFlowInfo);
        }

        //设置调整记录次数
        Example adjustQuery = new Example(CaseInfoAdjustRecord.class);
        adjustQuery.createCriteria().andEqualTo("caseId", caseId);
        int adCount = caseInfoAdjustRecordMapper.selectCountByExample(adjustQuery);
        vo.setAdjustCount("" + adCount);
        //获取分期延期信息 todo 正式有问题先注释掉
        //vo.setCaseDelayInstallments(caseDelayInstallmentService.delayInstallmentInfo(caseId));
        //人社条线调查取证结案添加判断

        if (TerritoryCodeEnum.RLSB.getCode().equals(caseMainInfo.getCaseTerritoryCode()) && CaseStageEnum.INVESTIGATION.getCode().equals(caseMainInfo.getCaseCurrentStageCode())) {
            String isOperateJabg = getIsOperateJabg(caseMainInfo);
            vo.setIsIsOperateJabg(isOperateJabg);
        }
        vo.setDataSource(caseMainInfo.getDataSource());
        return vo;
    }

    /**
     * 判断是否可以操作结案报告
     *
     * @param caseMainInfo
     * @return {@link boolean}
     * @author liyafeng
     * @date 2023/5/30
     */
    private String getIsOperateJabg(CaseMainInfoVo caseMainInfo) {
        String isOperateJabg = Constant.STRING_0;
        //查询当事人partId
        List<CasePartiesRecordVo> casePartiesRecordVos = casePartiesRecordService.getCasePartiesInfo(caseMainInfo.getId());
        Set<String> isOperateJabgSet = new LinkedHashSet<>();
        if (!ObjectUtils.isEmpty(casePartiesRecordVos)) {
            for (CasePartiesRecordVo casePartiesRecordVo : casePartiesRecordVos) {
                String flag = Constant.STRING_FALSE;
                //判断是否制作责令改正通知书或责令(限期)改正决定书
                CaseDocumentRecord zlgzCaseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseMainInfo.getId(), "DC2A0173300ZLGZTZS000000001", casePartiesRecordVo.getPartyId());
                if (!ObjectUtils.isEmpty(zlgzCaseDocumentRecord)) {
                    if (DocumentStatusEnum.CHECK_END.getCode().equals(zlgzCaseDocumentRecord.getDocumentApprovalStatus())) {
                        flag = Constant.STRING_TRUE;
                    }
                }
                if (Constant.STRING_TRUE.equals(flag)) {
                    isOperateJabgSet.add(flag);
                    continue;
                }
                CaseDocumentRecord zlqxCaseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseMainInfo.getId(), "DC2A0173300ZLXQGZJDS00000001", casePartiesRecordVo.getPartyId());
                if (!ObjectUtils.isEmpty(zlqxCaseDocumentRecord)) {
                    flag = Constant.STRING_TRUE;
                }
                isOperateJabgSet.add(flag);

            }
        }
        if (Constant.INTEGER_1 == isOperateJabgSet.size() && isOperateJabgSet.contains(Constant.STRING_TRUE)) {
            isOperateJabg = Constant.STRING_1;
        }
        return isOperateJabg;
    }


    /**
     * 描述：校验是否展示当事人选择器
     *
     * @param caseMainInfo {@link CaseMainInfoVo}
     * @param caseId       案件id
     * @return String 是否展示当事人选择器（0-否/1-是）
     * @author xiangyuyu
     * @date 2022-05-27 10:25
     */
    @Override
    public String validateIsShowPartiesSelector(CaseMainInfoVo caseMainInfo, String caseId) {
        if (validateIsNeedPassPartyId(caseMainInfo, caseId)) {
            return YesOrNoEnum.YES.getCode();
        } else {
            return YesOrNoEnum.NO.getCode();
        }
    }

    /**
     * 描述：校验是否需要单独传当事人id
     *
     * @param caseMainInfo {@link CaseMainInfoVo}
     * @param caseId       案件id
     * @return boolean 是否需要单独传当事人id(true-是/false-否)
     * @author xiangyuyu
     * @date 2022-05-27 10:25
     */
    @Override
    public boolean validateIsNeedPassPartyId(CaseMainInfoVo caseMainInfo, String caseId) {
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("未指定案件id-validateIsShowPartiesSelector");
            } else {
                caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            }
        }
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
        String handleType = caseMainInfo.getHandleType();

        String currentStageCode = caseMainInfo.getCaseCurrentStageCode();
        String currentLinkCode = caseMainInfo.getCaseCurrentLinkCode();
        List<String> exceptStageCodeList = new ArrayList<>();
        List<String> exceptLinkCodeList = new ArrayList<>();
        exceptStageCodeList.add("INVESTIGATION");
        exceptStageCodeList.add("CASE_REGISTER");
        exceptStageCodeList.add("CLOSE_ARCHIVING");
        exceptLinkCodeList.add("LINK-202203020942");
        if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                && HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                && !exceptStageCodeList.contains(currentStageCode)
                && !exceptLinkCodeList.contains(currentLinkCode)
        ) {
            return true;
        }
        return false;
    }

    /**
     * 描述：校验案件是否处于不可操作状态
     *
     * @param caseMainInfo {@link CaseMainInfoVo}
     * @param caseId       案件id
     * @return boolean 案件是否处于不可操作状态(true-是/false-否)
     * @author xiangyuyu
     * @date 2022-06-01 22:13
     */
    @Override
    public boolean validateCaseIsInNotDealStatus(CaseMainInfoVo caseMainInfo, String caseId) {
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("未指定案件id-validateCaseIsInNotDealStatus");
            } else {
                caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            }
        }
        String caseStatus = caseMainInfo.getCaseStatus();
        if (PREVENT_DEAL_CASE_STATUS_LIST.contains(caseStatus)) {
            return true;
        }
        return false;
    }

    /**
     * 描述：校验是否为案件中止状态时进行终止申请表相关操作
     *
     * @param caseMainInfo     {@link CaseMainInfoVo}
     * @param caseId           案件id
     * @param documentKindCode 操作文书种类编码
     * @return boolean 是否为案件中止状态时进行终止申请表相关操作(true-是/false-否)
     * @author xiangyuyu
     * @date 2022-07-14 13:54
     */
    @Override
    public boolean validateIsTerminateCaseWhenBreakOff(CaseMainInfoVo caseMainInfo, String caseId, String documentKindCode) {
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("未指定案件id-validateCaseIsInNotDealStatus");
            } else {
                caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            }
        }
        String caseStatus = caseMainInfo.getCaseStatus();
        if (CaseStatusEnum.SUSPEND.getCode().equals(caseStatus)
                && Constant.STRING_KIND_CODE_ZZSQB.equals(documentKindCode)) {
            return true;
        }
        return false;
    }

    /**
     * 描述：组装办案期限状态信息
     *
     * @param compareStartDate 比对开始日期
     * @param compareEndDate   比对结束日期
     * @return {@link Map<String,String> } 办案期限状态信息(描述对应颜色标识)
     * @author xiangyuyu
     * @date 2022-02-22 16:14
     */
    private Map<String, String> assembleCaseHandleDeadlineStatusInfo(LocalDate compareStartDate, LocalDate compareEndDate) {
        String status = "已到期";
        Map<String, String> map = new HashMap<>(2);

        String color = "orange";
        long count = compareEndDate.toEpochDay() - compareStartDate.toEpochDay();
        if (count > 0) {
            status = "剩" + count + "天";
            color = "green";
        } else if (count < 0) {
            status = "超" + (-count) + "天";
            color = "red";
        }
        map.put(status, color);
        return map;
    }

    /**
     * 【V1.0.0】描述：获取案件详情-当前阶段可操作的文书列表
     *
     * @param queryDto {@link CaseKeyInfoQueryDto}
     * @return {@link List<CaseDetailOperateDocInfoVo>} 案件详情-当前阶段可操作的文书列表
     * @author xiangyuyu
     * @date 2022-02-21 10:02
     */
    @Override
    public List<CaseDetailOperateDocInfoVo> getCouldBeOperateDocListCurrentStage(CaseKeyInfoQueryDto queryDto) {
        CaseMainInfoVo caseMainInfo = queryDto.getCaseMainInfo();
        String caseId;
        if (!ObjectUtils.isEmpty(caseMainInfo)) {
            caseId = caseMainInfo.getId();
        } else {
            caseId = queryDto.getCaseId();
            if (ObjectUtils.isEmpty(caseId)) {
                throw new BusinessException("未指定案件id");
            }
        }
        String documentTypeName = queryDto.getDocumentTypeName();
        if (!DocumentTypeEnum.isLegalEnumCode(documentTypeName)) {
            throw new BusinessException("未指定有效的文书类型名称");
        }
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();
        //获取当事人列表
        List<CasePartiesRecordVo> caseParties = casePartiesRecordService.getCasePartiesInfo(caseId);

        String caseStatus = caseMainInfo.getCaseStatus();
        String caseFlowCode = caseMainInfo.getCaseFlowCode();
        String caseFlowVersion = caseMainInfo.getCaseFlowVersion();
        String currentLinkCode = caseMainInfo.getCaseCurrentLinkCode();
        //获取单位参数配置是否配置了开启滞纳金
        SysDepartParam sysDepartParam = sysDepartParamService.getSysDepartParamByOrgCodeAndDeptCode(caseMainInfo.getCaseOrgCode(), caseMainInfo.getCaseDeptCode());
        String isLateFee = sysDepartParam.getIsLateFee();
        List<ConfigWorkFlowDocument> configWorkFlowDocumentList = configWorkFlowDocumentService.getConfigWorkFlowDocumentListByLinkCode(caseFlowCode, currentLinkCode, caseFlowVersion, documentTypeName, queryDto.getIsMobile());
        if (CaseStatusEnum.SUSPEND.getCode().equals(caseStatus)) {
            //终止申请表内容
            ConfigWorkFlowDocument zzsqbConfigInfo = null;
            for (ConfigWorkFlowDocument e : configWorkFlowDocumentList) {
                if (Constant.STRING_KIND_CODE_ZZSQB.equals(e.getDocumentKindCode())) {
                    zzsqbConfigInfo = e;
                    break;
                }
            }
            if (!ObjectUtils.isEmpty(zzsqbConfigInfo)) {
                //审批表
                configWorkFlowDocumentList = Arrays.asList(zzsqbConfigInfo);
            } else {
                //法律文书
                configWorkFlowDocumentList = new ArrayList<>();
            }
        }
        List<CaseDetailOperateDocInfoVo> caseDetailOperateDocInfoVoList = new ArrayList<>();
        UserDTO userDTO = UserUtil.getUserInfo();
        //获取当前用户的角色
        List<String> roleIdList = userRoleFeignApi.getRoleIdList(userDTO.getUserId().toString(), userDTO.getOrgCode());
        configWorkFlowDocumentList.forEach(e -> {
            boolean roleRight = false;
            if (roleIdList.contains(e.getOperateAuthRole())) {
                roleRight = true;
            }
            if (roleRight) {
                String documentLinkObjectType = e.getRelatedHolderType();
                String documentTypeId = e.getDocumentType();
                String documentCatalogCode = e.getDocumentCatalogCode();
                String documentKindCode = e.getDocumentKindCode();
                //关联文书不放在操作文书列表中
                if (YesOrNoEnum.NO.getCode().equals(e.getIsMatchDocument())) {
                    if (Constant.STRING_KIND_CODE_SDHZ.equals(documentKindCode)) {
                        return;
                    }
                    CaseDetailOperateDocInfoVo operateDocInfo = new CaseDetailOperateDocInfoVo();
                    operateDocInfo.setCaseId(caseId);
                    operateDocInfo.setDocumentCatalogCode(documentCatalogCode);
                    operateDocInfo.setDocumentKindCode(documentKindCode);
                    operateDocInfo.setDocumentKindName(e.getDocumentKindName());
                    MachDocumentInfoVo machDocumentInfoVo = getMachDocumentInfo(queryDto.getCaseMainInfo().getBusiParamId(), documentCatalogCode);
                    operateDocInfo.setMachDocumentInfoVo(machDocumentInfoVo);
                    //根据文书目录编码查询关联文书
                    List<String> allRelationDocCatalogCodeList = getALLRelationDocCatalogCodeList(caseMainInfo.getBusiParamId(), documentCatalogCode);
                    operateDocInfo.setAllRelationDocCatalogCodeList(allRelationDocCatalogCodeList);
                    //查看是否已经有生成对应的文书
                    CaseDocumentRecord caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, e.getDocumentCatalogCode());
                    //判断是否是撤回状态
                    if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
                        operateDocInfo.setDocumentId(caseDocumentRecord.getId());

                        String documentStatus = caseDocumentRecord.getDocumentRecordStatus();
                        if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(documentStatus)) {
                            caseDocumentRecord = null;
                        } else {
                            //有效的且已生成的文书
                            //组装 文书已经生成且待签字确认的关联当事人id列表
                            //根据案件id+文书种类编码查询文书记录
                            CaseDocumentRecordQueryDto queryDocument = new CaseDocumentRecordQueryDto();
                            queryDocument.setCaseId(caseId);
                            queryDocument.setDocumentKindCode(documentKindCode);
                            List<CaseDocumentRecordVo> documentRecordList = caseDocumentRecordService.getCaseDocumentRecordList(queryDocument);
                            List<String> docIsExistsAndWaitToSignRelatedPartyIdList = new ArrayList<>();
                            if (!ObjectUtils.isEmpty(documentRecordList) && documentRecordList.size() > 0) {
                                for (CaseDocumentRecordVo ele : documentRecordList) {
                                    String signStatus = ele.getDocumentSignstampedStatus();
                                    if (DocumentStatusEnum.WAIT_TO_CONFIRM.getCode().equals(signStatus)) {
                                        String partyIdInfo = ele.getPartyId();
                                        if (!ObjectUtils.isEmpty(partyIdInfo)) {
                                            if (partyIdInfo.indexOf(Constant.STRING_COMMA) > 0) {
                                                String[] arr = partyIdInfo.split(Constant.STRING_COMMA);
                                                docIsExistsAndWaitToSignRelatedPartyIdList.addAll(Arrays.asList(arr));
                                                break;
                                            } else {
                                                docIsExistsAndWaitToSignRelatedPartyIdList.add(partyIdInfo);
                                            }
                                        }
                                    }
                                }
                            }
                            operateDocInfo.setDocIsExistsAndWaitToSignRelatedPartyIdList(docIsExistsAndWaitToSignRelatedPartyIdList);
                        }
                    }
                    List<CasePartyRelateDocInfoVo> casePartiesKeyInfoVos = new ArrayList<>();
                    CasePartyRelateDocInfoVo casePartyRelateDocInfo;
                    for (CasePartiesRecordVo party : caseParties) {
                        casePartyRelateDocInfo = new CasePartyRelateDocInfoVo();
                        BeanUtils.copyProperties(party, casePartyRelateDocInfo);
                        casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.NO.getCode());
                        //查看该当事人是否已经添加该文书
                        Example queryCountExample = new Example(CaseDocumentRecord.class);
                        queryCountExample.createCriteria().andEqualTo("caseId", caseId)
                                .andEqualTo("documentCatalogCode", documentCatalogCode)
                                .andEqualTo("partyId", casePartyRelateDocInfo.getPartyId())
                                //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                                .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
                        int count = caseDocumentRecordMapper.selectCountByExample(queryCountExample);
                        if (count > 0) {
                            casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.YES.getCode());
                        }
                        casePartyRelateDocInfo.setIsAddedThisDocName(YesOrNoEnum
                                .getValueByCode(casePartyRelateDocInfo.getIsAddedThisDoc()));
                        casePartiesKeyInfoVos.add(casePartyRelateDocInfo);
                    }
                    operateDocInfo.setDocRelatePartiesList(casePartiesKeyInfoVos);
                    //判断是否是案件操作文书
                    boolean isCaseStatusChangeDoc = false;
                    if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(e.getDocumentKindCode())) {
                        isCaseStatusChangeDoc = true;
                        operateDocInfo.setCaseDocumentTypeFlag(Constant.STRING_1);
                    }
                    String handleType = caseMainInfo.getHandleType();
                    //陈述申辩复核意见书按钮控制处理
                    if (DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode().equals(documentKindCode)) {
                        //判断是否存在陈述申辩笔录
                        //没有陈述申辩笔录, 不显示陈述申辩复核意见书按钮
                        CaseDocumentRecordDto CSSBBLRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, DocumentKindEnum.DOC_KIND_DK2CSSBBL.getCode());
                        if (ObjectUtil.isEmpty(CSSBBLRecord)) {
                            return;
                        }
                    }
                    //文书是否处在不可处理的状态下（审批中）
                    boolean docIsOutOfDealStatus = false;
                    if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
                        String docStatus = caseDocumentRecord.getDocumentAuditStatus();
                        if ("pending".equals(docStatus)) {
                            docIsOutOfDealStatus = true;
                        }
                    }
                    //查询文书种类
                    List<ConfigBusiParamDocumentInfo> configList = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentCatalogCode(caseId, caseMainInfo, documentCatalogCode);
                    String kindCode;
                    if (!ObjectUtils.isEmpty(configList)) {
                        kindCode = configList.get(Constant.INTEGER_0).getDocumentKindCode();
                    } else {
                        throw new BusinessException("未匹配文书种类编码信息-caseId:" + caseId + ",documentCatalogCode:" + documentCatalogCode);
                    }
                    String busiParamId = caseMainInfo.getBusiParamId();
                    ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getConfigBusiParamDocumentInfoByBusiParamIdAndCode(busiParamId, operateDocInfo.getDocumentCatalogCode());
                    operateDocInfo.setIsNeedApproval(configBusiParamDocumentInfo.getIsApprove());
                    operateDocInfo.setDocumentLinkObjectType(configBusiParamDocumentInfo.getDocumentLinkObjectType());
                    if (DocumentTypeEnum.LAW_DOCUMENT.getCode().equals(documentTypeName)) {
                        //法律文书
                        //不在需要隐藏的法律文书列表当中
                        if (!OPERATE_HIDE_DOC_LIST.contains(kindCode)) {
                            if (HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                                    && PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                                //单案由多当事人分别处罚
                                //不在需要隐藏的文书列表当中(单案由多当事人分别处罚时需要隐藏的)
                                if (!MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.contains(documentKindCode)) {
                                    //判断是否为结案报告（需要特殊处理）
                                    if (Constant.STRING_KIND_CODE_JABG.equals(kindCode)) {
                                        //判断各个子流程都已进入到结案阶段
                                        if (checkIsAllSubFlowInAppointStage(caseId) && !docIsOutOfDealStatus) {
                                            caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                        }
                                    } else {
                                        if (!docIsOutOfDealStatus) {
                                            caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                        }
                                    }
                                }
                            } else {
                                //单当事人单案由、单当事人多案由、单案由多当事人合并处罚
                                if (!docIsOutOfDealStatus) {
                                    caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                }
                            }
                        }
                    } else {
                        //审批表
                        //判断是否为"可以改变案件状态"的法律文书
                        if (isCaseStatusChangeDoc) {
                            //判断是否是"中止xx审批表"
                            if (!CaseStatusChangeTypeEnum.SUSPEND.getDocumentKindCode().equals(documentKindCode)) {
                                //判断是否已经生成,未生成时，可以提供入口，已经生成过了，不再给入口
                                if (ObjectUtils.isEmpty(caseDocumentRecord) && !docIsOutOfDealStatus) {
                                    caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                }
                            } else {
                                caseDetailOperateDocInfoVoList.add(operateDocInfo);
                            }
                        } else {
                            if (HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                                    && PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                                //不在需要隐藏的文书列表当中(单案由多当事人分别处罚时需要隐藏的)
                                if (!MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.contains(documentKindCode) && !docIsOutOfDealStatus && !Constant.STRING_KIND_CODE_XZCFCXSPB.equals(kindCode)) {
                                    //单案由多当事人分别处罚
                                    caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                }
                            } else {
                                //单当事人单案由、单当事人多案由、单案由多当事人合并处罚
                                if (!docIsOutOfDealStatus) {
                                    //如果单位参数配置 配置了开启滞纳金  则不添加加处罚款审批表
                                    //剔除行政处罚撤销审批表
                                    if (!(PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType) && Constant.STRING_KIND_CODE_XZCFCXSPB.equals(kindCode))
                                            && !(Constant.STRING_1.equals(isLateFee) && Constant.STRING_KIND_CODE_JCFKSPB.equals(kindCode))
                                            //陈述申辩复核意见书只生成一次, 判断是否已经生成,未生成时，可以提供入口，已经生成过了，不再给入口
                                            && !(ObjectUtil.isNotEmpty(caseDocumentRecord) && DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode().equals(kindCode))) {
                                        caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
        return caseDetailOperateDocInfoVoList;
    }

    /**
     * 获取所有关联文书
     *
     * @param busiParamId
     * @param documentCatalogCode
     * @return {@link List< String>}
     * @author liyafeng
     * @date 2022/7/29
     */
    private List<String> getALLRelationDocCatalogCodeList(String busiParamId, String documentCatalogCode) {
        List<String> allRelationDocCatalogCodeList = new ArrayList<>();
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("busiParamId", busiParamId).andEqualTo("documentCatalogCode", documentCatalogCode).andEqualTo("isDeleted", "0");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            String allRelationDocCatalogCode = "";
            ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfos.get(0);
            if (StringUtils.isBlank(configBusiParamDocumentInfo.getRelationDocumentCatalogCode())) {
                allRelationDocCatalogCode = documentCatalogCode;
            } else {
                allRelationDocCatalogCode = documentCatalogCode + "," + configBusiParamDocumentInfo.getRelationDocumentCatalogCode();
            }
            allRelationDocCatalogCodeList = Arrays.asList(allRelationDocCatalogCode.split(","));
            //Collections.sort(allRelationDocCatalogCodeList, String::compareTo);
        }
        return allRelationDocCatalogCodeList;
    }

    /**
     * 获取所有配对的文书
     *
     * @author tianrunjia
     * @date 2022-08-30
     */
    private MachDocumentInfoVo getMachDocumentInfo(String busiParamId, String documentCatalogCode) {
        MachDocumentInfoVo machDocumentInfoVo = new MachDocumentInfoVo();
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("busiParamId", busiParamId).andEqualTo("documentCatalogCode", documentCatalogCode).andEqualTo("isDeleted", "0");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfos.get(0);
            machDocumentInfoVo.setMainDocumentCatalogName(configBusiParamDocumentInfo.getDocumentKindName());
            machDocumentInfoVo.setMainDocumentCatalogCode(configBusiParamDocumentInfo.getDocumentCatalogCode());
            if (StringUtils.isNotBlank(configBusiParamDocumentInfo.getRelationDocumentCatalogCode())) {
                String[] relationDocArray = configBusiParamDocumentInfo.getRelationDocumentCatalogCode().split(",");
                List<MachAssDocumentInfoVo> machAssDocumentInfoVoList = new ArrayList<>();
                for (int i = 0; i < relationDocArray.length; i++) {
                    ConfigBusiParamDocumentInfo busiParamDocumentInfo = configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(relationDocArray[i]);
                    if (!ObjectUtils.isEmpty(busiParamDocumentInfo)) {
                        MachAssDocumentInfoVo machAssDocumentInfoVo = new MachAssDocumentInfoVo();
                        machAssDocumentInfoVo.setMachDocumentCatalogCode(busiParamDocumentInfo.getDocumentCatalogCode());
                        machAssDocumentInfoVo.setMachDocumentCatalogName(busiParamDocumentInfo.getDocumentCatalogName());
                        machAssDocumentInfoVoList.add(machAssDocumentInfoVo);
                    }
                }
                machDocumentInfoVo.setMachAssDocumentInfoVoList(machAssDocumentInfoVoList);
            }
        }
        return machDocumentInfoVo;
    }

    /**
     * 描述：判断所有子流程是否都已进入到指定阶段
     *
     * @param caseId 案件id
     * @return boolean 所有子流程是否都已进入到指定阶段（true-是/false-否）
     * @author xiangyuyu
     * @date 2022-06-01 16:51
     */
    private boolean checkIsAllSubFlowInAppointStage(String caseId) {
        boolean flag = false;
        List<PartiesSubFlowInfoVo> partiesSubFlowInfo = getPartiesSubFlowInfo(caseId);
        int size = partiesSubFlowInfo.size();
        int count = 0;
        for (PartiesSubFlowInfoVo e : partiesSubFlowInfo) {
            String stageCode = e.getBranchStageCode();
            if ("CLOSE_ARCHIVING".equals(stageCode)) {
                count++;
            } else {
                break;
            }
        }
        if (count == size) {
            flag = true;
        }
        return flag;
    }

    /**
     * 【V1.6.0】描述：办结案件-优化版
     *
     * @param caseDto 入参
     * @return List<AllFinishCaseInfoVo>
     * @author tianrunjia
     * @date 2022/11/01
     **/
    @DS("punishRead")
    @Override
    public List<AllFinishCaseInfoVo> getAllFinishCaseInfoList(CaseQueryDto caseDto) {
        if (caseDto.getLength() > 1000) {
            throw new BusinessException("每页条数不能超过1000");
        }
        //处理当事人查询类别
        dealCaseQueryDto(caseDto);
        //失效日期判断
        //checkTimeColor(caseDto);
        //判断标签
        //checkCaseTag(caseDto);
        //机构判断
        checkOrgCode(caseDto);
        //限制区划查询
        handleLimitArea(caseDto);
        PageHelper.startPage(caseDto.getPageNum(), caseDto.getLength());
        List<AllFinishCaseInfoVo> list = caseMainInfoMapper.selectAllFinishCaseInfoList(caseDto);
        if (CollectionUtil.isEmpty(list)){
            return list;
        }
        // 查询案由信息
        List<String> caseIds = list.stream().map(AllFinishCaseInfoVo::getCaseId).collect(Collectors.toList());
        List<CaseReasonMainRecordByCaseIdVo> recordsByCaseIds = caseReasonMainRecordMapper.getRecordsByCaseIds(caseIds);
        List<CasePartiesRecord> casePartiesRecords = new ArrayList<>();
        List<CasePartiesLegalInfo> partiesLegalList = new ArrayList<>();
        List<CaseMainDetailSimpleInfo> caseMainDetailSimpleInfos = new ArrayList<>();
        // 如果是公安委托执法，查询案件当事人证件信息与交通信息
        if (StrUtil.equals(caseDto.getIsPublicSecurity(), "1")){
            getPartiesAndDetail(caseIds, casePartiesRecords, partiesLegalList, caseMainDetailSimpleInfos);
        }

        list.forEach(e -> {
            if(!Objects.equals(caseDto.getEntrust(), "0")){
                // 设置委托执法标签
                recordsByCaseIds.stream().filter(r -> Objects.equals(e.getCaseId(), r.getCaseId()))
                        .findFirst().ifPresent(info -> assembleEntrust(e, info));

                if (StrUtil.equals(caseDto.getIsPublicSecurity(), "1")){
                    //设置交通信息
                    caseMainDetailSimpleInfos.stream().filter(data -> Objects.equals(data.getCaseId(), e.getCaseId()))
                            .findFirst().ifPresent(info -> assembleTrafficInfo(info, e));
                    //设置当事人的证据信息
                    casePartiesRecords.stream().filter(data -> Objects.equals(data.getCaseId(), e.getCaseId()))
                            .findFirst().ifPresent(info -> assemblePartiesInfo(info, partiesLegalList, e));
                }
            }

            String caseId = e.getCaseId();
            //1.循环设置处理人员
            Example example = new Example(CaseHandlePersonRecord.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
            List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(example);
            for (CaseHandlePersonRecord caseHandlePersonRecord : handlePersonRecords) {
                if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                    e.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                } else if (Constant.STRING_2.equals(caseHandlePersonRecord.getHandlePersonType())) {
                    e.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                }

            }
            e.setHandlePersonName(e.getMainHandlePerson() + "、" + e.getHelpHandlePerson());

            e.setCaseReason(convertParamQueryFinish(e.getCaseReason()));
            e.setIllegalLevel(convertParamQueryFinish(e.getIllegalLevel()));
            e.setCaseType(convertParamQueryFinish(e.getCaseType()));
            e.setCaseStatus(convertParamQueryFinish(e.getCaseStatus()));
            e.setCaseNumber(convertParamQueryFinish(e.getCaseNumber()));
            e.setCaseSource(convertParamQueryFinish(e.getCaseSource()));
            e.setCaseRegistTime(convertParamQueryFinish(e.getCaseRegistTime()));
            e.setCaseTimeLimit(convertParamQueryFinish(e.getCaseTimeLimit()));
            e.setCaseVerdictEndTime(convertParamQueryFinish(e.getCaseVerdictEndTime()));
            e.setDocumentNumber(convertParamQueryFinish(e.getDocumentNumber()));
            e.setCaseEndTime(convertParamQueryFinish(e.getCaseEndTime()));
            e.setPunishKinds(convertParamQueryFinish(e.getPunishKinds()));
            e.setExecuteWay(convertParamQueryFinish(e.getExecuteWay()));
            e.setHandleOrgName(convertParamQueryFinish(e.getHandleOrgName()));
            e.setHandleDeptName(convertParamQueryFinish(e.getHandleDeptName()));
            e.setCaseCreateTime(convertParamQueryFinish(e.getCaseCreateTime()));
            e.setCasePartiesReasonType(convertParamQueryFinish(e.getCasePartiesReasonType()));

            //TODO
            //多案由金额特殊处理
            if (PartiesReasonTypeEnum.MULTIPLE_REASONS.getCode().equals(e.getCasePartiesReasonType())) {
                e.setConfiscateIllegalMoney(convertMoneyQueryFinish(e.getConfiscateIllegalMoney()));
                e.setDraftPunishMoney(convertMoneyQueryFinish(e.getDraftPunishMoney()));
            } else {
                e.setConfiscateIllegalMoney(convertParamQueryFinish(e.getConfiscateIllegalMoney()));
                e.setDraftPunishMoney(convertParamQueryFinish(e.getDraftPunishMoney()));
            }
            e.setCaseActsCode(convertParamQueryFinish(e.getCaseActsCode()));
            e.setCaseExternalActsCode(convertParamQueryFinish(e.getCaseExternalActsCode()));
            e.setCaseBarCodeUrl(convertParamQueryFinish(e.getCaseBarCodeUrl()));
            e.setCaseQrCodeUrl(convertParamQueryFinish(e.getCaseQrCodeUrl()));
            e.setCaseTerritoryCode(convertParamQueryFinish(e.getCaseTerritoryCode()));
            //String handPersonName = handlePersonRecords.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
            //vo.setHandlePersonName(handPersonName);

            //3.caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
            e.setCaseType(CaseTypeEnum.getValueByCode(e.getCaseType()));
            //4.非法人则将当事人唯一标识置空
            if (!(StringUtils.isNotEmpty(e.getPartyType()) && e.getPartyType().equals(Constant.STRING_2))) {
                e.setPartyIdentityCode("");
            }
            //5. 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
            e.setCaseStatus(CaseStatusEnum.getValueByCode(e.getCaseStatus()));

            //多案由
            /*if(Constant.STRING_2.equals(e.getCasePartiesReasonType())){
                CaseReasonMainRecordQueryDto dto = new CaseReasonMainRecordQueryDto();
                dto.setCaseId(caseId);
                dto.setStatus("1");
                List<CaseReasonMainRecordVo> vos = caseReasonMainRecordService.getCaseReasonRecordList(dto);
                if (vos.size() > 1){
                    StringJoiner joiner = new StringJoiner("；");
                    for (CaseReasonMainRecordVo reasonMainRecordVo: vos) {
                        joiner.add(reasonMainRecordVo.getCaseReasonName());
                    }
                    e.setCaseReason(joiner.toString());
                }
            }*/

            //当事人
            /*Example exampleParty = new Example(CasePartiesRecord.class);
            exampleParty.createCriteria().andEqualTo("caseId",caseId).andEqualTo("status",Constant.STRING_1);
            List<CasePartiesRecord> casePartiesRecordList = casePartiesRecordMapper.selectByExample(exampleParty);
            if(casePartiesRecordList.size()>0){
                if(Constant.STRING_3.equals(e.getCasePartiesReasonType())){
                    e.setPartyName(casePartiesRecordList.get(0).getPartyName() + "等" + casePartiesRecordList.size() + "个" );
                }else {
                    e.setPartyName(casePartiesRecordList.get(0).getPartyName());
                }
            }*/
            if (StringUtils.isNotBlank(e.getPartyName())) {
                if (e.getPartyName().indexOf(";") > 0) {
                    String[] partyNameArray = e.getPartyName().split(";");
                    Set<String> partySets = Arrays.stream(partyNameArray).collect(Collectors.toSet());
                    /*if (partySets.size() == 1) {
                        e.setPartyName(partySets.toArray()[0].toString());
                    } else {
                        e.setPartyName(partySets.toArray()[0].toString() + "等" + partySets.size() + "个");
                    }*/
                    if (partySets.size() > 0) {
                        e.setPartyName(CollUtil.join(partySets, ","));
                    }
                }
            } else {
                e.setPartyName("");
            }

            //计算罚款金额
            double draftPunishMoney, confiscateIllegalMoney;
            if (StringUtils.isNotBlank(e.getDraftPunishMoney())) {
                draftPunishMoney = Float.valueOf(e.getDraftPunishMoney());
            } else {
                draftPunishMoney = 0.00;
            }
            if (StringUtils.isNotBlank(e.getConfiscateIllegalMoney())) {
                confiscateIllegalMoney = Float.valueOf(e.getConfiscateIllegalMoney());
            } else {
                confiscateIllegalMoney = 0.00;
            }
            DecimalFormat dfmt = new DecimalFormat("##0.00");
            e.setPunishMoney(dfmt.format(draftPunishMoney + confiscateIllegalMoney));
            /*// 处罚金额 ,分别处罚处理处罚金额
            if (HandleTypeEnum.PART_PUNISH.getCode().equals(e.getHandleType())){
                vo.setPunishMoney(vo.getPunishMoney());
            }*/
            //如果是人社和应急条线，去查询案由
            if (TerritoryCodeEnum.RLSB.getCode().equals(e.getCaseTerritoryCode()) || TerritoryCodeEnum.YJGL.getCode().equals(e.getCaseTerritoryCode())) {
                CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.getRsAndYjReason(caseId);
                if (caseMainDetailInfo != null && StrUtil.isNotEmpty(caseMainDetailInfo.getCaseEmergencyReasonContent())) {
                    String caseEmergencyReasonContent = caseMainDetailInfo.getCaseEmergencyReasonContent();
                    List<CaseEmergencyReasonInfoDto> emergencyReasonList = JSON.parseArray(caseEmergencyReasonContent, CaseEmergencyReasonInfoDto.class);
                    List<String> reasonNameList = CollUtil.newArrayList();
                    emergencyReasonList.forEach(u -> reasonNameList.add(u.getEmergencyReasonName()));
                    e.setOtherReasonNames(CollUtil.join(reasonNameList, ","));
                } else if (caseMainDetailInfo != null && StrUtil.isNotEmpty(caseMainDetailInfo.getPersonReasonName())) {
                    e.setOtherReasonNames(caseMainDetailInfo.getPersonReasonName());
                }
            }
        });
        return list;
    }

    /**
     * 组装是否委托执法信息
     * @param e
     * @param caseReasonMainRecord
     */
    private void assembleEntrust(AllFinishCaseInfoVo e, CaseReasonMainRecordByCaseIdVo caseReasonMainRecord) {
        e.setHadEntrustCase(true);
        e.setSxTypeStr("委托执法");
        e.setClientOrgName(StrUtil.isBlank(caseReasonMainRecord.getClientDeptName()) ? caseReasonMainRecord.getClientOrgName() : caseReasonMainRecord.getClientDeptName());
        e.setPublicSecurityItemCode(caseReasonMainRecord.getPublicSecurityItemCode());
    }

    /**
     * 设置交通信息
     * @param info
     * @param vo
     */
    private void assembleTrafficInfo(CaseMainDetailSimpleInfo info, AllFinishCaseInfoVo vo){
        vo.setLicenseFileNumber(info.getLicenseFileNumber());
        vo.setTrafficWay(info.getTrafficWay());
        vo.setLicensePlateNumber(info.getLicensePlateNumber());
    }

    /**
     * 设置当事人的证件信息
     * @param record
     * @param partiesLegalList
     * @param vo
     */
    private void assemblePartiesInfo(CasePartiesRecord record, List<CasePartiesLegalInfo> partiesLegalList, AllFinishCaseInfoVo vo){
        if (Objects.equals(record.getPartyType(), "1")){
            // 个人
            vo.setIdentityType(CertTypeEnum.getValueByCode(record.getPartyIdentityType()));
            vo.setIdentityNumber(record.getPartyIdentityCode());
        }else {
            // 如果是法人，那么就要从法人列表中筛选
            partiesLegalList.stream().filter(data -> Objects.equals(data.getId(), record.getPartyId()))
                    .findFirst().ifPresent(legalInfo -> assembleLegalInfo(vo, legalInfo));
        }
    }

    /**
     * 组装法人信息
     * @param vo
     * @param legalInfo
     */
    private void assembleLegalInfo(AllFinishCaseInfoVo vo, CasePartiesLegalInfo legalInfo){
        vo.setUniscId(legalInfo.getUniscid());
        vo.setIdentityType(CertTypeEnum.getValueByCode(legalInfo.getLegalCertType()));
        vo.setIdentityNumber(legalInfo.getLegalCertNo());
    }

    /**
     * 查询案件当事人证件信息与交通信息
     * @param caseIds
     * @param casePartiesRecords
     * @param partiesLegalList
     * @param caseMainDetailSimpleInfos
     */
    private void getPartiesAndDetail(List<String> caseIds, List<CasePartiesRecord> casePartiesRecords, List<CasePartiesLegalInfo> partiesLegalList, List<CaseMainDetailSimpleInfo> caseMainDetailSimpleInfos) {
        // 通过案件id得到案件当事人记录信息
        Example partiesRecordExample = new Example(CasePartiesRecord.class);
        partiesRecordExample.createCriteria().andIn("caseId", caseIds);
        casePartiesRecords.addAll(casePartiesRecordMapper.selectByExample(partiesRecordExample));
        // 把当事人为单位的过滤出来，并获取对应的法人信息
        List<CasePartiesRecord> partiesLegalRecordList = casePartiesRecords.stream().filter(pr -> !Objects.equals(pr.getPartyType(), Constant.STRING_1)).collect(Collectors.toList());
        List<String> legalIdList = partiesLegalRecordList.stream().map(CasePartiesRecord::getPartyId).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(legalIdList)){
            Example legalExample = new Example(CasePartiesLegalInfo.class);
            legalExample.createCriteria().andIn("id", legalIdList);
            partiesLegalList.addAll(casePartiesLegalInfoMapper.selectByExample(legalExample));
        }
        // 获取简单案件详情宽表中的交通信息
        Example simpleDetailExample = new Example(CaseMainDetailSimpleInfo.class);
        simpleDetailExample.createCriteria().andIn("caseId", caseIds);
        caseMainDetailSimpleInfos.addAll(caseMainDetailSimpleInfoMapper.selectByExample(simpleDetailExample));
    }

    /**
     * 处理限制区域
     * @param caseDto
     */
    private void handleLimitArea(CaseQueryDto caseDto){
        if (StringUtils.isEmpty(caseDto.getEnforceRegiCode())) {
            return;
        }
        String enforceRegiCode = caseDto.getEnforceRegiCode();
        //先清空查询限制，若查询全市数据则不限制数据查询
        caseDto.setEnforceRegiCode(null);
        if (Constant.STRING_1.equals(caseDto.getEnforceRegiLevel())) {
            //重庆查询全市数据时，不用调用接口，根据前两位查询即可
            caseDto.setEnforceRegiCode(enforceRegiCode.substring(0, 2));
            return;
        }
        caseDto.setAreaCodes(limitArea(enforceRegiCode));
    }


    /**
     * 限制区划查询
     * @param areaCode 区域码
     * @return 下级code集合
     */
    public List<String> limitArea(String areaCode) {
        // 调用检查端接口查询本级以及下级的code
        Map<String, Object> params = new HashMap<>();
        params.put("areaCode", areaCode);
        Map<String, String> headers = HeaderUtil.headerInfo();
        String response = HttpUtil.createGet(memberUrl.concat(getAreaListByAreaCode))
                .addHeaders(headers).form(params).execute().body();
        Result result = JSONObject.parseObject(response, Result.class);
        if (HttpStatus.HTTP_OK == result.getCode() && !ObjectUtils.isEmpty(result.getData())) {
            List<MemberAreaVo> areas = JSON.parseArray(result.getData().toString(), MemberAreaVo.class);
            return areas.stream().map(MemberAreaVo::getAreaCode)
                    .filter(Objects::nonNull).distinct().collect(Collectors.toList());
        }
        throw new BusinessException(result.getMessage());
    }

    private String convertParamQueryFinish(String param) {
        if (StringUtils.isNotBlank(param) && param.indexOf(";") >= 0) {
            if (";".equals(param)) {
                return "";
            } else {
                return param.substring(0, param.indexOf(";"));
            }
        } else {
            return param;
        }
    }

    private String convertMoneyQueryFinish(String param) {
        //多案由处罚金额处理
        if (StringUtils.isNotBlank(param) && param.indexOf(";") >= 0) {
            if (";".equals(param)) {
                return "";
            } else {
                try {
                    BigDecimal money = new BigDecimal("0");
                    String[] split = param.split(";");
                    for (int i = 0; i < split.length; i++) {
                        String str = split[i];
                        if (!ObjectUtils.isEmpty(str)) {
                            money = money.add(new BigDecimal(str));
                        }
                    }
                    if (money.compareTo(BigDecimal.ZERO) != 0) {
                        money = money.divide(new BigDecimal("2"), BigDecimal.ROUND_CEILING);
                    }
                    return money.toString();
                } catch (Exception exception) {
                    log.error("金额格式错误");
                    return param.substring(0, param.indexOf(";"));
                }
            }
        } else {
            return param;
        }
    }

    /**
     * 【V1.6.0】描述：办结案件、全部待办查询列表-优化版
     *
     * @param caseDto 入参
     * @return List<TaskVo>
     * @author tianrunjia
     * @date 2022/11/01
     **/
    @Override
    public List<AllCaseInfoListVo> getAllCaseInfoList(CaseQueryDto caseDto) {
        if (caseDto.getLength() > 200) {
            throw new BusinessException("每页条数不能超过200");
        }
        //处理当事人查询类别
        //dealCaseQueryDto(caseDto);
        //失效日期判断
        //checkTimeColor(caseDto);
        //判断标签
        //checkCaseTag(caseDto);
        //机构判断
        //checkOrgCode(caseDto);
        PageHelper.startPage(caseDto.getPageNum(), caseDto.getLength());
        List<AllCaseInfoListVo> list = caseMainInfoMapper.selectAllCaseInfokList(caseDto);
        list.forEach(e -> {
            String caseId = e.getCaseId();
            //1.循环设置处理人员
            Example example = new Example(CaseHandlePersonRecord.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
            List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(example);
            for (CaseHandlePersonRecord caseHandlePersonRecord : handlePersonRecords) {
                if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                    e.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                } else if (Constant.STRING_2.equals(caseHandlePersonRecord.getHandlePersonType())) {
                    e.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                }
            }

            //String handPersonName = handlePersonRecords.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
            //vo.setHandlePersonName(handPersonName);
            //鉴定 中止与恢复 办案期限计算
            if (!Constant.STRING_3.equals(e.getCaseStatus())) {
                CaseMainInfoStatusChangeRecord record = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(caseId, CaseStatusChangeTypeEnum.SUSPEND.getCode());
                if (null != record) {
                    //暂停，则原有的办案期限+（当前日期-中止日期）
                    if (Constant.STRING_1.equals(record.getStatus())) {
                        long days = DateUtil.calculatePastDays(record.getChangeEffectTime().toLocalDate());
                        e.setCaseTimeLimit(DateUtils.addDays(e.getCaseTimeLimit(), (int) days));
                    }
                    //恢复，则原有的办案期限+（恢复日期-中止日期）
                }
            }

            //2.计算剩余时间
            e.setTimeColor("");
            /*if( e.getCaseTimeLimit()!=null && e.getCaseVerdictEndTime()==null){
                int timeLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), e.getCaseTimeLimit());
                handleRemainTimes(timeLimit, e);
                //3.红橙黄绿蓝
                if (timeLimit <= Constant.INTEGER_3) {
                    e.setTimeColor("red");
                } else if (timeLimit <= Constant.INTEGER_15) {
                    e.setTimeColor("yellow");
                } else if (timeLimit > Constant.INTEGER_15) {
                    e.setTimeColor("blue");
                }
            }*/

            //3.caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
            e.setCaseType(CaseTypeEnum.getValueByCode(e.getCaseType()));
            //4.非法人则将当事人唯一标识置空
            if (!(StringUtils.isNotEmpty(e.getPartyType()) && e.getPartyType().equals(Constant.STRING_2))) {
                e.setPartyIdentityCode("");
            }
            //5. 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
            e.setCaseStatus(CaseStatusEnum.getValueByCode(e.getCaseStatus()));

            //多案由
            /*if(Constant.STRING_2.equals(e.getCasePartiesReasonType())){
                CaseReasonMainRecordQueryDto dto = new CaseReasonMainRecordQueryDto();
                dto.setCaseId(caseId);
                dto.setStatus("1");
                List<CaseReasonMainRecordVo> vos = caseReasonMainRecordService.getCaseReasonRecordList(dto);
                if (vos.size() > 1) {
                    StringJoiner joiner = new StringJoiner("；");
                    for (CaseReasonMainRecordVo reasonMainRecordVo: vos) {
                        joiner.add(reasonMainRecordVo.getCaseReasonName());
                    }
                    e.setCaseReason(joiner.toString());
                }
            }*/
            //多当事人
            if (Constant.STRING_3.equals(e.getCasePartiesReasonType())) {
                Example exampleParty = new Example(CasePartiesRecord.class);
                exampleParty.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
                int pn = casePartiesRecordMapper.selectCountByExample(exampleParty);
                if (pn > 1) {
                    e.setPartyType("multitude");
                    List<CasePartiesRecordVo> casePartiesRecords = casePartiesRecordService.getCasePartiesInfo(caseId);
                    e.setPartyName(casePartiesRecords.get(0).getPartyName() + "等" + pn + "个");
                }
            }

            //计算罚款金额
            double draftPunishMoney, confiscateIllegalMoney;
            if (StringUtils.isNotBlank(e.getDraftPunishMoney())) {
                draftPunishMoney = Float.valueOf(e.getDraftPunishMoney());
            } else {
                draftPunishMoney = 0.00;
            }
            if (StringUtils.isNotBlank(e.getConfiscateIllegalMoney())) {
                confiscateIllegalMoney = Float.valueOf(e.getConfiscateIllegalMoney());
            } else {
                confiscateIllegalMoney = 0.00;
            }
            e.setPunishMoney(String.valueOf(draftPunishMoney + confiscateIllegalMoney));
            /*// 处罚金额 ,分别处罚处理处罚金额
            if (HandleTypeEnum.PART_PUNISH.getCode().equals(e.getHandleType())){
                vo.setPunishMoney(vo.getPunishMoney());
            }*/
        });
        return list;
    }

    /**
     * 【V1.0.0】描述：工作台--代办任务列表+全部任务
     *
     * @param caseDto 入参
     * @return List<TaskVo>
     * @author lxj
     * @date 2022/2/18
     **/
    @Override
    public List<TaskVo> getApproveTaskList(CaseQueryDto caseDto) {
        if (caseDto.getLength() > 200) {
            throw new BusinessException("每页条数不能超过200");
        }
        //处理当事人查询类别
        dealCaseQueryDto(caseDto);
        //失效日期判断
        checkTimeColor(caseDto);
        //判断标签
        checkCaseTag(caseDto);
        //机构判断
        checkOrgCode(caseDto);
        PageHelper.startPage(caseDto.getPageNum(), caseDto.getLength());
        List<TaskVo> list = caseMainInfoMapper.getApproveTaskList(caseDto);
        if (list != null && list.size() > 0) {
            for (TaskVo vo : list) {
                String caseId = vo.getCaseId();
                //1.循环设置处理人员
                Example example = new Example(CaseHandlePersonRecord.class);
                example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
                example.orderBy("handlePersonType").asc();
                List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(example);
                for (CaseHandlePersonRecord caseHandlePersonRecord : handlePersonRecords) {
                    if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                        vo.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                    } else if (Constant.STRING_2.equals(caseHandlePersonRecord.getHandlePersonType())) {
                        vo.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                    }
                }
                String handPersonName = handlePersonRecords.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
                vo.setHandlePersonName(handPersonName);
                //鉴定 中止与恢复 办案期限计算
                CaseMainInfoStatusChangeRecord record = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(caseId, CaseStatusChangeTypeEnum.SUSPEND.getCode());
                if (null != record) {
                    //暂停，则原有的办案期限+（当前日期-中止日期）
                    if (Constant.STRING_1.equals(record.getStatus())) {
                        long days = DateUtil.calculatePastDays(record.getChangeEffectTime().toLocalDate());
                        vo.setCaseTimeLimit(DateUtils.addDays(vo.getCaseTimeLimit(), (int) days));
                    }
                    //恢复，则原有的办案期限+（恢复日期-中止日期）
                }
                //2.计算剩余时间
                vo.setTimeColor("");
                if (vo.getCaseTimeLimit() != null && vo.getCaseVerdictEndTime() == null) {
                    int timeLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), vo.getCaseTimeLimit());
                    handleRemainTimes(timeLimit, vo);
                    //3.红橙黄绿蓝
                    if (timeLimit <= Constant.INTEGER_3) {
                        vo.setTimeColor("red");
                    } else if (timeLimit <= Constant.INTEGER_15) {
                        vo.setTimeColor("yellow");
                    } else if (timeLimit > Constant.INTEGER_15) {
                        vo.setTimeColor("blue");
                    } else {
                        //vo.setTimeColor("blue");
                    }
                } else {
//                    vo.setTimeColor("blue");
                }

                //4.caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
                vo.setCaseType(CaseTypeEnum.getValueByCode(vo.getCaseType()));
                //5.如果是公司主体，返回公司信息
                if (StringUtils.isNotEmpty(vo.getPartyType()) && vo.getPartyType().equals(Constant.STRING_2)) {
                    CasePartiesLegalInfo legalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(vo.getPartyId());
                    vo.setLegalInfo(legalInfo);
                }
                //6. 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
                vo.setCaseStatus(CaseStatusEnum.getValueByCode(vo.getCaseStatus()));
                //多当事人多案由处理
                // 多当事人企业详情
                CaseReasonMainRecordQueryDto dto = new CaseReasonMainRecordQueryDto();
                dto.setCaseId(caseId);
                dto.setStatus("1");
                List<CaseReasonMainRecordVo> vos = caseReasonMainRecordService.getCaseReasonRecordList(dto);
                if (vos.size() > 1) {
                    StringJoiner joiner = new StringJoiner("；");
                    for (CaseReasonMainRecordVo reasonMainRecordVo : vos) {
                        joiner.add(reasonMainRecordVo.getCaseReasonName());
                    }
                    vo.setCaseReason(joiner.toString());
                }
                Example exampleParty = new Example(CasePartiesRecord.class);
                exampleParty.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
                int pn = casePartiesRecordMapper.selectCountByExample(exampleParty);
                if (pn > 1) {
                    vo.setPartyType("multitude");
                    List<CasePartiesRecordVo> casePartiesRecords = casePartiesRecordService.getCasePartiesInfo(caseId);
                    vo.setPartyName(casePartiesRecords.get(0).getPartyName() + "等" + pn + "个");
                    vo.setLegalInfo(null);
                }
                // 处罚金额 ,分别处罚处理处罚金额
                if (HandleTypeEnum.PART_PUNISH.getCode().equals(vo.getHandleType())) {
                    vo.setPunishMoney(vo.getPunishMoney());
                }

            }
        }
        return list;
    }

    /**
     * 【V1.0.0】描述：颜色统计
     *
     * @param caseDto 入参
     * @return ColorSumVo
     * @author lxj
     * @date 2022/2/22
     **/
    @Override
    public ColorSumVo getColorStatistics(CaseQueryDto caseDto) {
        //处理当事人查询类别
        dealCaseQueryDto(caseDto);
        //分红（当前日期-办案期限<0)、黄(当前日期-办案期限<=7)、蓝色(当前日期-办案期限>7)
        //判断标签
        checkCaseTag(caseDto);
        //机构判断
        checkOrgCode(caseDto);
        //int total = caseMainInfoMapper.getApproveTaskListOld(caseDto).size();
        int total = caseMainInfoMapper.getApproveTaskList(caseDto).size();
        //caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 3));
        caseDto.setTimeLimitEnd(BaseUtil.getNowTimeStamp());
        caseDto.setTimeLimitStart(Timestamp.valueOf("1999-01-01 00:00:00"));
        int red = caseMainInfoMapper.getColorStatistics(caseDto);
        /*caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 0));
        caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 3));
        int orange = caseMainInfoMapper.getColorStatistics(caseDto);*/
        caseDto.setTimeLimitStart(BaseUtil.getNowTimeStamp());
        caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 7));
        /*caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 4));
        caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 15));*/
        int yellow = caseMainInfoMapper.getColorStatistics(caseDto);
        //caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 16));
        caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 7));
        caseDto.setTimeLimitEnd(null);
        //caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 90));
        int blue = caseMainInfoMapper.getColorStatistics(caseDto);
        //caseDto.setBlue("BLUE");
        //int blue = caseMainInfoMapper.getColorStatistics(caseDto);
        ColorSumVo sumVo = new ColorSumVo();
        //sumVo.setBlueNum(blue);
        sumVo.setBlueNum(blue);
        //sumVo.setGreenNum(green);
        //sumVo.setOrangeNum(orange);
        sumVo.setRedNum(red);
        sumVo.setYellowNum(yellow);
        sumVo.setTotal(total);
        return sumVo;
    }

    /**
     * 【V1.0.0】描述：根据案件id查询案件主要信息
     *
     * @param caseId 案件id
     * @return {@link CaseMainInfoVo} 案件主要信息
     * @author xiangyuyu
     * @date 2022-02-22 09:33
     */
    @Override
    public CaseMainInfoVo getCaseMainInfo(String caseId) {
        log.info("getCaseMainInfo start(caseId:+" + caseId + ")...");
        CaseMainInfoVo vo = caseMainInfoMapper.selectCaseMainInfo(caseId);
        if (ObjectUtils.isEmpty(vo)) {
            throw new BusinessException("未找到案件信息");
        }
        log.info("getCaseMainInfo end-vo:" + vo);
        return vo;
    }

    /**
     * 【V1.0.0】描述：根据案件id查询案件阶段流转记录信息（包含文书、附件）
     *
     * @param caseId 案件id
     * @return {@link List<CaseStageFlowRecordInfoVo>} 案件阶段流转记录信息（包含文书、附件）
     * @author xiangyuyu
     * @date 2022-02-22 20:15
     */
   /*   @Override
    public List<CaseStageFlowRecordInfoVo> getCaseStageFlowRecord_old(String caseId) {
        List<CaseStageFlowRecordInfoVo> caseStageFlowRecordInfoList = new ArrayList<>();
        List<CaseStageRelateLinkVo> caseStageRelateLinkList = new ArrayList<>();
        List<CaseMainFlowRecord> caseMainFlowRecordList = caseMainFlowRecordMapper.selectCaseStageRecordByCaseId(caseId);
        String latestStageCode = "";
        //阶段
        CaseStageFlowRecordInfoVo caseStageFlowRecordInfo = new CaseStageFlowRecordInfoVo();
        //环节
        CaseStageRelateLinkVo caseStageRelateLink;
        for (int i = 0; i < caseMainFlowRecordList.size(); i++) {
            CaseMainFlowRecord record = caseMainFlowRecordList.get(i);
            String stageCode = record.getCaseStageCode();
            String stageName = record.getCaseStageName();
            if (!stageCode.equals(latestStageCode)) {
                latestStageCode = stageCode;
                //不同一个阶段
                if (caseStageRelateLinkList.size() > 0) {
                    //非首次进入循环
                    //环节列表完整加入当前阶段记录
                    caseStageFlowRecordInfo.setCaseStageRelateLinkList(caseStageRelateLinkList);
                    caseStageFlowRecordInfoList.add(caseStageFlowRecordInfo);
                    //重置
                    caseStageRelateLinkList = new ArrayList<>();
                    caseStageFlowRecordInfo = new CaseStageFlowRecordInfoVo();
                }
                caseStageFlowRecordInfo.setStageCode(stageCode);
                caseStageFlowRecordInfo.setStageName(stageName);

                caseStageRelateLink = new CaseStageRelateLinkVo();
                String linkCode = record.getCaseLinkCode();
                String linkName = record.getCaseLinkName();
                caseStageRelateLink.setLinkId(linkCode);
                caseStageRelateLink.setLinkName(linkName);
            } else {
                //同一个阶段
                //新建环节
                caseStageRelateLink = new CaseStageRelateLinkVo();
                String linkCode = record.getCaseLinkCode();
                String linkName = record.getCaseLinkName();
                caseStageRelateLink.setLinkId(linkCode);
                caseStageRelateLink.setLinkName(linkName);
            }
            //环节关联文书信息查询
            CaseStageLinkRelateDocumentQueryDto queryDto = new CaseStageLinkRelateDocumentQueryDto();
            queryDto.setCaseId(caseId);
            queryDto.setCaseStageCode(stageCode);
            queryDto.setCaseLinkCode(caseStageRelateLink.getLinkId());
            List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList
                    = caseDocumentRecordService.getCaseStageLinkRelateDocumentInfo(queryDto);
            caseStageRelateLink.setCaseRelateDocumentList(caseStageLinkRelateDocumentList);
            //加入环节列表
            caseStageRelateLinkList.add(caseStageRelateLink);
            if (i == caseMainFlowRecordList.size() - 1) {
                caseStageFlowRecordInfo.setCaseStageRelateLinkList(caseStageRelateLinkList);
                caseStageFlowRecordInfoList.add(caseStageFlowRecordInfo);
            }
            CaseStageFlowRecordInfoVo appendStageInfo = new CaseStageFlowRecordInfoVo();
        }
        return caseStageFlowRecordInfoList;
    }*/


    /**
     * 【V1.0.0】描述：根据案件id查询案件阶段流转记录信息（包含文书、附件）
     *
     * @param caseId 案件id
     * @return {@link List<CaseStageFlowRecordInfoVo>} 案件阶段流转记录信息（包含文书、附件）
     * @author xiangyuyu
     * @date 2022-02-22 20:15
     */
    @Override
    public List<CaseStageFlowRecordInfoVo> getCaseStageFlowRecord(String caseId) {

        //案件基础信息
        CaseMainInfoVo caseMainInfo = getCaseMainInfo(caseId);

        //案源不予立案
        if (CaseStatusEnum.PUNISH_NO_REGISTER.getCode().equals(caseMainInfo.getCaseStatus()) && ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
            List<CaseStageFlowRecordInfoVo> voList = getCaseSourceStageFlowRecord(caseMainInfo);
            return voList;
        }
        //案件案由、当事人类型
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();

        List<CaseStageFlowRecordInfoVo> caseStageFlowRecordInfoList = new ArrayList<>();

        //List<WorkFlowRollRecordInfo> caseMainFlowRecordList = workFlowRollRecordInfoService.getWorkRollRecordEffectiveByWorkId(caseId);
        List<WorkFlowRollSubRecordInfo> workFlowRollSubRecordInfoList = workFlowRollSubRecordInfoService.getAllWorkRollSubRecordEffectiveByWorkId(caseId);
        List<String> stageCodeList = new ArrayList<>();
        for (int i = 0; i < workFlowRollSubRecordInfoList.size(); i++) {
            WorkFlowRollSubRecordInfo record = workFlowRollSubRecordInfoList.get(i);
            if (stageCodeList.contains(record.getWorkStageCode())) {
                continue;
            } else {
                stageCodeList.add(record.getWorkStageCode());
            }
            //环节关联文书信息查询
            CaseStageLinkRelateDocumentQueryDto queryDto = new CaseStageLinkRelateDocumentQueryDto();
            queryDto.setCaseId(caseId);
            queryDto.setCaseStageCode(record.getWorkStageCode());
            //queryDto.setCaseLinkCode(record.getCaseLinkCode());
            List<CaseStageLinkRelateDocumentVo> oldCaseStageLinkRelateDocumentList
                    = caseDocumentRecordService.getCaseStageLinkRelateDocumentInfo(queryDto);
            List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList = new ArrayList<>();
            oldCaseStageLinkRelateDocumentList.forEach(e -> {
                if (DocumentRecordStatusEnum.NORMAL.getCode().equals(e.getDocumentRecordStatus())) {
                    caseStageLinkRelateDocumentList.add(e);
                }
            });

            //文书关联附件信息查询
            caseStageLinkRelateDocumentList.forEach(e -> {
                String documentCatalogCode = e.getDocumentCatalogCode();
                AuditDetailDocumentQueryDto queryAttachment = new AuditDetailDocumentQueryDto();
                queryAttachment.setCaseId(caseId);
                queryAttachment.setDocumentCatalogCode(documentCatalogCode);
                queryAttachment.setPartyId(e.getPartyId());
                List<DocAttachmentsVo> attachmentsList = caseAppendixRecordService.getDocLinkAttachments(queryAttachment);
                List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
                attachmentsList.forEach(a -> {
                    DocumentRelateAttachmentVo vo = new DocumentRelateAttachmentVo();
                    BeanUtils.copyProperties(a, vo);
                    vo.setAttachmentId(a.getId());
                    vo.setAttachmentTitle(a.getAppendixName());
                    if (AttachmentTypeEnum.SENT_RECEIPT.getCode().equals(a.getAppendixTypeCode())) {
                        if (!ObjectUtils.isEmpty(a.getPartyId())) {
                            Example queryExample = new Example(CasePartiesRecord.class);
                            queryExample.createCriteria().andEqualTo("partyId", a.getPartyId());
                            List<CasePartiesRecord> casePartiesRecord = casePartiesRecordMapper.selectByExample(queryExample);
                            if (!ObjectUtils.isEmpty(casePartiesRecord)) {
                                vo.setAttachmentTitle(a.getAppendixType() + "(" + casePartiesRecord.get(0).getPartyName() + ")");
                            }
                        }
                        vo.setAttachmentTitle(a.getAppendixType());
                    }
                    vo.setAttachmentUrl(a.getAppendixUrl());
                    documentRelateAttachmentList.add(vo);
                });
                e.setDocumentRelateAttachmentList(documentRelateAttachmentList);


                //多当事人案件中，文书中配置关联对象为当事人的，文书列表中标题中增加当事人名称展示。示例：电子送达地址确认书（张三）。
                String partyId = e.getPartyId();
                if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                        && DocumentLinkObjectTypeEnum.PERSON.getCode().equals(e.getDocumentLinkObjectType())
                        && (!ObjectUtils.isEmpty(partyId) && !partyId.contains(","))) {
                    //多当事人合并处罚不拼接当事人名称
                    //查询当事人名称
                    List<CasePartiesRecordVo> casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
                    String partyName = "";
                    for (CasePartiesRecordVo ele : casePartiesRecordList) {
                        String tmpPartyId = ele.getPartyId();
                        if (partyId.equals(tmpPartyId)) {
                            partyName = ele.getPartyName();
                            break;
                        }
                    }
                    e.setDocumentKindName(e.getDocumentKindName() + "(" + partyName + ")");
                }

            });

            CaseStageFlowRecordInfoVo caseStageFlowRecordInfoVo = new CaseStageFlowRecordInfoVo();
            caseStageFlowRecordInfoVo.setStageCode(record.getWorkStageCode());
            caseStageFlowRecordInfoVo.setStageName(record.getWorkStageName());
            caseStageFlowRecordInfoVo.setCaseStageLinkRelateDocumentVoList(caseStageLinkRelateDocumentList);

            caseStageFlowRecordInfoList.add(caseStageFlowRecordInfoVo);

        }
        return caseStageFlowRecordInfoList;
    }

    private List<CaseStageFlowRecordInfoVo> getCaseSourceStageFlowRecord(CaseMainInfoVo caseMainInfo) {
        List<CaseStageFlowRecordInfoVo> voList = new ArrayList<>();
        CaseStageFlowRecordInfoVo caseStageFlowRecordInfoVo = new CaseStageFlowRecordInfoVo();
        caseStageFlowRecordInfoVo.setStageCode(Constant.CASE_SOURCE_STAGE_CODE);
        caseStageFlowRecordInfoVo.setStageName(Constant.CASE_SOURCE_STAGE_NAME);
        Example partyExample = new Example(CaseSourcePartyInfo.class);
        partyExample.createCriteria().andEqualTo("caseSourceId", caseMainInfo.getId()).andEqualTo("status", Constant.STRING_1);
        List<CaseSourcePartyInfo> caseSourcePartyInfos = caseSourcePartyInfoMapper.selectByExample(partyExample);
        CaseSourceLinkRelateDocumentQueryDto query = new CaseSourceLinkRelateDocumentQueryDto();
        query.setCaseSourceId(caseMainInfo.getId());
        query.setDocumentRecordStatus(Constant.STRING_1);
        List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList = caseSourceDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
        for (CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo : caseStageLinkRelateDocumentList) {
            //多当事人并且文书针对人
            if (Constant.STRING_2.equals(caseStageLinkRelateDocumentVo.getDocumentLinkObjectType()) && caseSourcePartyInfos.size() > 1) {
                String partyId = caseStageLinkRelateDocumentVo.getPartyId();
                String[] partyIdArr = partyId.split(",");
                if (partyIdArr.length == 1) {
                    CaseSourcePartyInfo caseSourcePartyInfo = caseSourcePartyInfoMapper.selectByPrimaryKey(partyId);
                    if (null != caseSourcePartyInfo) {
                        String documentCatalogName = caseStageLinkRelateDocumentVo.getDocumentCatalogName() + "(" + caseSourcePartyInfo.getPartyName() + ")";
                        caseStageLinkRelateDocumentVo.setDocumentCatalogName(documentCatalogName);
                    }
                }
            }
        }

        //附件查询
        Example materialExample = new Example(CaseSourceMaterialRecord.class);
        materialExample.createCriteria().andEqualTo("caseSourceId", caseMainInfo.getId()).andEqualTo("isDelete", Constant.STRING_0);
        List<CaseSourceMaterialRecord> caseSourceMaterialRecordList = caseSourceMaterialRecordMapper.selectByExample(materialExample);
        List<CaseStageLinkRelateDocumentVo> materialList = new ArrayList<>();
        caseSourceMaterialRecordList.forEach(caseSourceMaterialRecord -> {
            CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo = new CaseStageLinkRelateDocumentVo();
            caseStageLinkRelateDocumentVo.setDocumentUrl(caseSourceMaterialRecord.getMaterialUrl());
            caseStageLinkRelateDocumentVo.setDocumentId(caseSourceMaterialRecord.getId());
            caseStageLinkRelateDocumentVo.setDocumentCreateTime(caseSourceMaterialRecord.getUploadTime());
            caseStageLinkRelateDocumentVo.setCreateUserName(caseSourceMaterialRecord.getUploadUserName());
            caseStageLinkRelateDocumentVo.setDocumentCatalogName(caseSourceMaterialRecord.getMaterialName());
            caseStageLinkRelateDocumentVo.setDocumentKindName(caseSourceMaterialRecord.getMaterialName());
            materialList.add(caseStageLinkRelateDocumentVo);
        });
        caseStageLinkRelateDocumentList.addAll(materialList);
        caseStageFlowRecordInfoVo.setCaseStageLinkRelateDocumentVoList(caseStageLinkRelateDocumentList);
        voList.add(caseStageFlowRecordInfoVo);
        return voList;
    }

    /**
     * 【V1.0.0】描述：公用-根据案件id查询案件简要基础信息
     *
     * @param caseId 案件id
     * @return {@link CaseBasicInfoVo} 案件简要基础信息
     * @author xiangyuyu
     * @date 2022-02-23 10:47
     */
    @Override
    public CaseBasicInfoVo getCaseBasicInfo(String caseId) {

        //案件基础信息
        CaseMainInfoVo caseMainInfo = getCaseMainInfo(caseId);
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            throw new BusinessException("未找到案件信息");
        }
        //案源不予立案
        if (CaseStatusEnum.PUNISH_NO_REGISTER.getCode().equals(caseMainInfo.getCaseStatus()) && ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
            CaseBasicInfoVo vo = getCaseSourceBasicInfoVo(caseMainInfo);
            return vo;
        }
        CaseBasicInfoVo vo = new CaseBasicInfoVo();
        vo.setCaseId(caseId);
        vo.setCaseType(caseMainInfo.getCaseType());
        vo.setIsCaseSourceByla(Constant.STRING_0);
        //获取当事人信息
        // 多当事人修改
        List<CasePartiesRecordVo> partiesRecords = casePartiesRecordService.getCasePartiesInfo(caseId);
        if (partiesRecords.size() == 0) {
            throw new BusinessException("案件当事人信息为空");
        }
        String partyTitle;
        List<CasePartiesLegalInfoVo> partiesLegalInfoVos = new ArrayList<>();
        List<CasePartiesPersonInfoVo> partiesPersonInfoVos = new ArrayList<>();
        vo.setIsLegalInfoShortage("NO");
        if (partiesRecords.size() == 1) {
            vo.setPartyTypeId(partiesRecords.get(0).getPartyType());
            vo.setPartyTypeName(PartyTypeEnum.getValueByCode(partiesRecords.get(0).getPartyType()));
            partyTitle = partiesRecords.get(0).getPartyName();
            String partyType = partiesRecords.get(0).getPartyType();
            String partyId = partiesRecords.get(0).getPartyId();
            setPartyInformation(partiesLegalInfoVos, partiesPersonInfoVos, partyType, partyId, vo);
        } else {
            vo.setPartyTypeId("multitude");
            partyTitle = partiesRecords.get(0).getPartyName() + "等" + partiesRecords.size() + "个当事人";
            for (CasePartiesRecordVo rv : partiesRecords) {
                setPartyInformation(partiesLegalInfoVos, partiesPersonInfoVos, rv.getPartyType(), rv.getPartyId(), vo);
            }
        }

        vo.setPartyTitle(partyTitle);
        vo.setCasePartiesLegalInfo(partiesLegalInfoVos);
        vo.setCasePartiesPersonInfo(partiesPersonInfoVos);

        //案由
        // 多案由修改
        //if (!Constant.HUMAN_SOCIETY_BARS_CODE.equals(caseMainInfo.getCaseTerritoryCode())) {
        CaseReasonMainRecordQueryDto caseReasonMainRecordQueryDto = new CaseReasonMainRecordQueryDto();
        caseReasonMainRecordQueryDto.setCaseId(caseId);
        caseReasonMainRecordQueryDto.setStatus("1");
        List<CaseReasonMainRecordVo> caseReasonMainRecords = caseReasonMainRecordService.getCaseReasonRecordList(caseReasonMainRecordQueryDto);
        if (!ObjectUtils.isEmpty(caseReasonMainRecords)) {
            StringJoiner reasonCodeJoin = new StringJoiner(";");
            StringJoiner reasonNameJoin = new StringJoiner(";");
            for (CaseReasonMainRecordVo recordVo : caseReasonMainRecords) {
                reasonCodeJoin.add(recordVo.getCaseReasonCode());
                reasonNameJoin.add(recordVo.getCaseReasonName());
            }
            vo.setCaseReasonCode(reasonCodeJoin.toString());
            vo.setCaseReasonName(reasonNameJoin.toString());
        } else {
            vo.setCaseReasonCode("");
            vo.setCaseReasonName("");
        }
        //}
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        if (!ObjectUtils.isEmpty(caseMainDetailInfo.getPersonReasonId())) {
            //vo.setCaseHandlePersonList();
        }
        //办案人员列表
        List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
        vo.setCaseHandlePersonList(caseHandlePersonRecordList);
        if (!ObjectUtils.isEmpty(caseHandlePersonRecordList) && caseHandlePersonRecordList.size() > 0) {
            caseHandlePersonRecordList.forEach(e -> {
                if (HandlePersonTypeEnum.MAIN.getCode().equals(e.getHandlePersonType())) {
                    String caseHandlingDeptInfo = e.getHandleOrgName() + "/" + e.getHandleDeptName();
                    //办案部门
                    vo.setCaseHandlingDeptInfo(caseHandlingDeptInfo);
                    return;
                }
            });
        }
        return vo;
    }

    /**
     * 案源不予立案信息
     *
     * @param caseMainInfo
     * @return
     * @author liyafeng
     * @date 2022/8/19
     */
    private CaseBasicInfoVo getCaseSourceBasicInfoVo(CaseMainInfoVo caseMainInfo) {
        CaseBasicInfoVo vo = new CaseBasicInfoVo();
        vo.setCaseId(caseMainInfo.getId());
        vo.setIsCaseSourceByla(Constant.STRING_1);
        //获取当事人信息
        // 多当事人修改
        Example example = new Example(CaseSourcePartyInfo.class);
        example.createCriteria().andEqualTo("caseSourceId", caseMainInfo.getId()).andEqualTo("status", Constant.STRING_1);
        List<CaseSourcePartyInfo> caseSourcePartyInfos = caseSourcePartyInfoMapper.selectByExample(example);
        CaseSourceRegisterMainInfo caseSourceRegisterMainInfo = caseSourceRegisterMainInfoMapper.selectByPrimaryKey(caseMainInfo.getId());
        String partyTitle = caseSourceRegisterMainInfo.getPartyName();
        vo.setPartyTitle(partyTitle);
        List<CasePartiesLegalInfoVo> casePartiesLegalInfoVos = new ArrayList<>();
        List<CasePartiesPersonInfoVo> partiesPersonInfoVos = new ArrayList<>();
        if (caseSourcePartyInfos.size() == 1) {
            vo.setPartyTypeId(caseSourcePartyInfos.get(0).getPartyType());
            vo.setPartyTypeName(PartyTypeEnum.getValueByCode(caseSourcePartyInfos.get(0).getPartyType()));
        }
        if (null != caseSourcePartyInfos && caseSourcePartyInfos.size() > 0) {
            caseSourcePartyInfos.forEach(caseSourcePartyInfo -> {
                if (PartyTypeEnum.PERSON.getCode().equals(caseSourcePartyInfo.getPartyType())) {
                    CasePartiesPersonInfoVo casePartiesPersonInfoVo = new CasePartiesPersonInfoVo();
                    casePartiesPersonInfoVo.setHeadshotUrl("https://csoss-test.oss-cn-shanghai.aliyuncs.com/cs/2022/0307/head.jpeg");
                    casePartiesPersonInfoVo.setCertType(caseSourcePartyInfo.getPartyIdentityType());
                    casePartiesPersonInfoVo.setAddress(caseSourcePartyInfo.getAddress());
                    casePartiesPersonInfoVo.setAddressAreas(caseSourcePartyInfo.getAddressAreas().split(","));
                    casePartiesPersonInfoVo.setBirth(caseSourcePartyInfo.getPersonBirth());
                    casePartiesPersonInfoVo.setCertNo(caseSourcePartyInfo.getPartyIdentityCode());
                    casePartiesPersonInfoVo.setId(caseSourcePartyInfo.getId());
                    casePartiesPersonInfoVo.setJob(caseSourcePartyInfo.getJob());
                    casePartiesPersonInfoVo.setMobile(caseSourcePartyInfo.getMobile());
                    casePartiesPersonInfoVo.setName(caseSourcePartyInfo.getPartyName());
                    casePartiesPersonInfoVo.setSex(caseSourcePartyInfo.getPersonSex());
                    casePartiesPersonInfoVo.setUnitName(caseSourcePartyInfo.getPersonUnitName());
                    partiesPersonInfoVos.add(casePartiesPersonInfoVo);
                }
                if (PartyTypeEnum.LEGAL.getCode().equals(caseSourcePartyInfo.getPartyType())) {
                    CasePartiesLegalInfoVo casePartiesLegalInfoVo = new CasePartiesLegalInfoVo();
                    BeanUtils.copyProperties(caseSourcePartyInfo, casePartiesLegalInfoVo);
                    casePartiesLegalInfoVo.setHeadshotUrl("https://csoss-test.oss-cn-shanghai.aliyuncs.com/cs/2022/0307/head.jpeg");
                    casePartiesLegalInfoVo.setEntName(caseSourcePartyInfo.getPartyName());
                    casePartiesLegalInfoVo.setId(caseSourcePartyInfo.getId());
                    casePartiesLegalInfoVo.setPhone(caseSourcePartyInfo.getMobile());
                    casePartiesLegalInfoVo.setUniscid(caseSourcePartyInfo.getPartyIdentityCode());
                    casePartiesLegalInfoVos.add(casePartiesLegalInfoVo);
                }
            });
        }
        vo.setCasePartiesLegalInfo(casePartiesLegalInfoVos);
        vo.setCasePartiesPersonInfo(partiesPersonInfoVos);
        //办案人员列表
        List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseMainInfo.getId());
        vo.setCaseHandlePersonList(caseHandlePersonRecordList);
        if (!ObjectUtils.isEmpty(caseHandlePersonRecordList) && caseHandlePersonRecordList.size() > 0) {
            caseHandlePersonRecordList.forEach(e -> {
                if (HandlePersonTypeEnum.MAIN.getCode().equals(e.getHandlePersonType())) {
                    String caseHandlingDeptInfo = e.getHandleOrgName() + "/" + e.getHandleDeptName();
                    //办案部门
                    vo.setCaseHandlingDeptInfo(caseHandlingDeptInfo);
                    return;
                }
            });
        }
        return vo;
    }

    /**
     * 多当事人列表填充
     *
     * @param partiesLegalInfoVos
     * @param partiesPersonInfoVos
     * @param partyType
     * @param partyId
     */
    private void setPartyInformation(List<CasePartiesLegalInfoVo> partiesLegalInfoVos, List<CasePartiesPersonInfoVo> partiesPersonInfoVos, String partyType, String partyId, CaseBasicInfoVo vo) {
        if (PartyTypeEnum.PERSON.getCode().equals(partyType)) {
            CasePartiesPersonInfoVo partiesPersonInfoVo = new CasePartiesPersonInfoVo();
            CasePartiesPersonInfo casePartiesPersonInfo = casePartiesPersonInfoMapper.selectByPrimaryKey(partyId);
            BeanUtils.copyProperties(casePartiesPersonInfo, partiesPersonInfoVo);
            partiesPersonInfoVo.setHeadshotUrl("https://csoss-test.oss-cn-shanghai.aliyuncs.com/cs/2022/0307/head.jpeg");
            // 证件类型
            for (CertTypeEnum cert : CertTypeEnum.values()) {
                if (cert.getCode().equals(partiesPersonInfoVo.getCertType())) {
                    partiesPersonInfoVo.setCertType(cert.getDes());
                }
            }
            partiesPersonInfoVos.add(partiesPersonInfoVo);
        }
        if (PartyTypeEnum.LEGAL.getCode().equals(partyType)) {
            CasePartiesLegalInfo partiesLegalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(partyId);
            if (StringUtils.isBlank(partiesLegalInfo.getLegalCertNo()) || StringUtils.isBlank(partiesLegalInfo.getLegalCertType())) {
                vo.setIsLegalInfoShortage("YES");
            }
            CasePartiesLegalInfoVo legalInfoVo = new CasePartiesLegalInfoVo();
            BeanUtils.copyProperties(partiesLegalInfo, legalInfoVo);
            legalInfoVo.setHeadshotUrl("https://csoss-test.oss-cn-shanghai.aliyuncs.com/cs/2022/0307/head.jpeg");
            partiesLegalInfoVos.add(legalInfoVo);
        }
    }

    /**
     * 【V1.0.0】描述：获取案件详情-阶段信息
     *
     * @param caseId 案件id
     * @return {@link List<CaseDetailStageInfoVo>} 案件详情-阶段信息
     * @author xiangyuyu
     * @date 2022-02-23 21:37
     */
    @Override
    public List<CaseDetailStageInfoVo> getCaseDetailStageInfo(String caseId) {
        ConfigDictionaryInfoQueryDto queryDto = new ConfigDictionaryInfoQueryDto();
        queryDto.setDicFieldCode(Constant.STRING_CASE_STAGE);
        queryDto.setIsEffective(YesOrNoEnum.YES.getCode());
        List<ConfigDictionaryInfoVo> stageList = configDictionaryInfoService.getConfigDictionaryList(queryDto);
        if (ObjectUtils.isEmpty(stageList)) {
            throw new BusinessException("未配置阶段数据字典");
        }
        //添加虚拟阶段（已归档）
        ConfigDictionaryInfoVo configDictionaryInfo = new ConfigDictionaryInfoVo();
        configDictionaryInfo.setDicCode("stage_end_virtual");
        configDictionaryInfo.setDicName("已归档");
        stageList.add(configDictionaryInfo);

        //获取案件环节记录信息
        List<WorkFlowRollRecordInfo> caseMainFlowRecordList = workFlowRollRecordInfoService.getWorkRollRecordEffectiveByWorkId(caseId);
        CaseDetailStageInfoVo stageInfo;
        List<CaseDetailStageInfoVo> caseDetailStageInfoList = new ArrayList<>();
        //组装各阶段名信息
        for (ConfigDictionaryInfoVo e : stageList) {
            stageInfo = new CaseDetailStageInfoVo();
            stageInfo.setStageId(e.getDicCode());
            stageInfo.setStageName(e.getDicName());
            stageInfo.setStageIsFinish(YesOrNoEnum.NO.getCode());
            stageInfo.setStageIsFinishName(YesOrNoEnum.NO.getDes());
            stageInfo.setIsCurrentStageCode(YesOrNoEnum.NO.getCode());
            stageInfo.setIsCurrentStageName(YesOrNoEnum.NO.getDes());
            caseDetailStageInfoList.add(stageInfo);
        }
        List<String> allStageCodeList = new ArrayList<>();
        caseDetailStageInfoList.forEach(e -> {
            allStageCodeList.add(e.getStageId());
        });

        //已生成阶段记录的阶段编码列表
        List<String> generatedStageCodeList = new ArrayList<>();
        //需要展示时间的阶段信息
        Map<String, CaseDetailStageInfoVo> needShowTimeStageInfo = new HashMap<>(8);

        //跳过阶段编码列表
        List<String> jumpStageCodeList = new ArrayList<>();
        allStageCodeList.forEach(e -> {
            if (!generatedStageCodeList.contains(e)) {
                jumpStageCodeList.add(e);
            }
        });
        jumpStageCodeList.remove("stage_end_virtual");
        //当前环节记录没有生成时取上个阶段的结束时间
        LocalDateTime latestStageEndTime = null;
        for (WorkFlowRollRecordInfo e : caseMainFlowRecordList) {
            String stageCode = e.getWorkStageCode();
            LocalDateTime startTime = e.getWorkStageStartTime();
            LocalDateTime endTime = e.getWorkStageEndTime();
            LocalDateTime tmpTime = ObjectUtils.isEmpty(endTime) ? startTime : endTime;
            CaseDetailStageInfoVo stageInfoVo = new CaseDetailStageInfoVo();
            stageInfoVo.setStageId(stageCode);
            stageInfoVo.setShowTime(tmpTime);
            latestStageEndTime = tmpTime;
            stageInfoVo.setStageIsFinish(ObjectUtils.isEmpty(endTime) ? YesOrNoEnum.NO.getCode() : YesOrNoEnum.YES.getCode());
            needShowTimeStageInfo.put(stageCode, stageInfoVo);
            if (generatedStageCodeList.contains(stageCode)) {
                continue;
            } else {
                generatedStageCodeList.add(stageCode);
            }
        }
        //需要展示时间的阶段编号列表
        List<String> needShowTimeStageCodeList = new ArrayList<>();
        for (Map.Entry<String, CaseDetailStageInfoVo> entry : needShowTimeStageInfo.entrySet()) {
            needShowTimeStageCodeList.add(entry.getKey());
        }
        CaseMainInfoVo caseMainInfo = getCaseMainInfo(caseId);
        //案件当前阶段
        String caseCurrentStageCode = caseMainInfo.getCaseCurrentStageCode();
        //案件当前环节
        String caseCurrentLinkName = caseMainInfo.getCaseCurrentLinkName();
        LocalDateTime finalLatestStageEndTime = latestStageEndTime;
        caseDetailStageInfoList.forEach(e -> {
            String stageId = e.getStageId();
            if (generatedStageCodeList.contains(stageId)) {
                CaseDetailStageInfoVo stageInfoVo = needShowTimeStageInfo.get(stageId);
                e.setShowTime(stageInfoVo.getShowTime());
                e.setStageIsFinish(stageInfoVo.getStageIsFinish());
                e.setStageIsFinishName(YesOrNoEnum.getValueByCode(e.getStageIsFinish()));
                if (caseCurrentStageCode.equals(stageId)) {
                    if ("CLOSE_ARCHIVING".equals(caseCurrentStageCode)
                            && YesOrNoEnum.YES.getCode().equals(e.getStageIsFinish())
                            && "归档".equals(caseCurrentLinkName)) {
                        caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 1).setShowTime(caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 2).getShowTime());
                        caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 1).setIsCurrentStageCode(YesOrNoEnum.YES.getCode());
                        caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 1).setIsCurrentStageName(YesOrNoEnum.YES.getDes());
                        caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 1).setStageIsFinish(YesOrNoEnum.YES.getCode());
                        caseDetailStageInfoList.get(caseDetailStageInfoList.size() - 1).setStageIsFinishName(YesOrNoEnum.YES.getDes());
                    } else {
                        e.setIsCurrentStageCode(YesOrNoEnum.YES.getCode());
                        e.setIsCurrentStageName(YesOrNoEnum.getValueByCode(e.getIsCurrentStageCode()));
                    }
                }
            } else {
                //没有生成当前环节滚动记录
                if (stageId.equals(caseCurrentStageCode)) {
                    e.setShowTime(finalLatestStageEndTime);
                    e.setIsCurrentStageCode(YesOrNoEnum.YES.getCode());
                    e.setIsCurrentStageName(YesOrNoEnum.getValueByCode(e.getIsCurrentStageCode()));
                }
            }
        });
        if (ObjectUtils.isEmpty(generatedStageCodeList) || generatedStageCodeList.size() == 0) {
            LocalDateTime caseCreateTime = caseMainInfo.getCaseCreateTime();
            if (!ObjectUtils.isEmpty(caseCreateTime)) {
                caseDetailStageInfoList.get(Constant.INTEGER_0).setIsCurrentStageCode(YesOrNoEnum.YES.getCode());
                caseDetailStageInfoList.get(Constant.INTEGER_0).setIsCurrentStageName(YesOrNoEnum.YES.getDes());
                caseDetailStageInfoList.get(Constant.INTEGER_0).setStageIsFinish(YesOrNoEnum.NO.getCode());
                caseDetailStageInfoList.get(Constant.INTEGER_0).setStageIsFinishName(YesOrNoEnum.NO.getDes());
            }
        }
        return caseDetailStageInfoList;
    }

    /**
     * 时效判断
     *
     * @param caseDto 入参
     * @return
     * @author lxj
     * @date 2022/2/28
     **/
    private void checkTimeColor(CaseQueryDto caseDto) {
        //分红（当前日期-办案期限<0)、黄(当前日期-办案期限<=7)、蓝色(当前日期-办案期限>7)
        // 红橙黄绿蓝
        if (StringUtils.isEmpty(caseDto.getTimeColor())) {
            return;
        }
        if ("red".equals(caseDto.getTimeColor())) {
            caseDto.setCaseTimeColor("red");
            /*caseDto.setTimeLimitStart(Timestamp.valueOf("1999-01-01 00:00:00"));
            caseDto.setTimeLimitEnd(BaseUtil.getNowTimeStamp());*/
            //caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 3));
        } /*else if ("orange".equals(caseDto.getTimeColor())) {
            caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(new Date(), 0));
            caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(new Date(), 3));
        }*/ else if ("yellow".equals(caseDto.getTimeColor())) {
            caseDto.setCaseTimeColor("yellow");
            /*caseDto.setTimeLimitStart(BaseUtil.getNowTimeStamp());
            caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 7));*/
            //caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 4));
            //caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 15));
        } else if ("blue".equals(caseDto.getTimeColor())) {
            //caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 16));
            /*caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 7));
            caseDto.setTimeLimitEnd(null);*/
            caseDto.setCaseTimeColor("blue");
        }
    }

    /**
     * tag标签处理
     *
     * @param caseDto
     * @return void
     * @author lxj
     * @date 2022/2/28
     **/
    private void checkCaseTag(CaseQueryDto caseDto) {
        if (StringUtils.isEmpty(caseDto.getCaseTag())) {
            return;
        }
        List<String> tagList = new ArrayList<>();
        String[] str = caseDto.getCaseTag().split(",");
        for (String s : str) {
            tagList.add(s);
        }
        caseDto.setTagList(tagList);
    }


    /**
     * orgCode处理
     *
     * @param caseDto
     * @return void
     * @author lxj
     * @date 2022/3/31
     **/
    private void checkOrgCode(CaseQueryDto caseDto) {
        caseDto.setOrg(0);
        if (StringUtils.isEmpty(caseDto.getOrgCode())) {
            return;
        }
        List<String> orgCodeList = new ArrayList<>();
        List<String> deptCodeList = new ArrayList<>();
        String[] str = caseDto.getOrgCode().split(",");

        for (String s : str) {
            if (s.indexOf("_") > 0) {
                orgCodeList.add(s);
            } else {
                orgCodeList.add(s);
            }
        }
        if (orgCodeList.size() > 0 && deptCodeList.size() > 0) {
            caseDto.setOrg(1);
        } else if (orgCodeList.size() > 0) {
            caseDto.setOrg(2);
        } else if (deptCodeList.size() > 0) {
            caseDto.setOrg(3);
        }

        caseDto.setOrgCodeList(orgCodeList);
        caseDto.setDeptCodeList(deptCodeList);
    }

    /**
     * 计算超出时间--办案日期，裁决完毕日期
     *
     * @param timeLimit
     * @param vo
     * @return void
     * @author lxj
     * @date 2022/3/1
     **/
    private void handleRemainTimes(int timeLimit, TaskVo vo) {
        //办案期限
        if (timeLimit == Constant.INTEGER_0) {
            //vo.setRemainTime("已到期");
            vo.setRemainTime("截止日");
        } else if (timeLimit > Constant.INTEGER_0) {
            vo.setRemainTime("剩余" + timeLimit + "天");
        } else {
            vo.setRemainTime("超" + String.valueOf(timeLimit).substring(Constant.INTEGER_1) + "天");
        }

        if (CaseStatusEnum.SUSPEND.getCode().equals(vo.getCaseStatus())) {
            vo.setRemainTime("暂停");
        }

        if (vo.getCaseVerdictEndTime() == null) {
            return;
        }
        //裁决期限
        int verdictLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), vo.getCaseVerdictEndTime());
        if (verdictLimit == Constant.INTEGER_0) {
            vo.setRemainVerdictTime("已到期");
        } else if (verdictLimit > Constant.INTEGER_0) {
            vo.setRemainVerdictTime("剩余" + verdictLimit + "天");
        } else {
            vo.setRemainVerdictTime("超" + String.valueOf(verdictLimit).substring(Constant.INTEGER_1) + "天");
        }

    }

    /**
     * 判断案件是否为多当事人分别处罚案件
     *
     * @return {@link boolean}
     * @author: zhengqiang
     * @date: 2022/5/18
     * @param: caseId
     * @param: caseMainInfo 案件信息
     **/
    @Override
    public boolean checkCaseIsPartiesPartPunish(String caseId, CaseMainInfoVo caseMainInfo) {
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            caseMainInfo = getCaseMainInfo(caseId);
        }
        if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(caseMainInfo.getCasePartiesReasonType())
                && HandleTypeEnum.PART_PUNISH.getCode().equals(caseMainInfo.getHandleType())) {
            return true;
        }
        return false;
    }

    /**
     * 案件主信息更新-流程信息更新
     *
     * @author: tianrunjia
     * @date: 2022/5/18
     * @param: caseId
     **/
    @Override
    public void doModCaseMainInfoWithCaseFlowRoll(CaseMainInfo caseMainInfo) {
        caseMainInfoMapper.updateByPrimaryKeySelective(caseMainInfo);
    }

    /**
     * 【V2.0.0】描述：获取案件当事人子流程信息
     *
     * @param caseId 案件id
     * @return {@link List<PartiesSubFlowInfoVo>} 案件当事人子流程信息
     * @author xiangyuyu
     * @date 2022-05-28 20:08
     */
    @Override
    public List<PartiesSubFlowInfoVo> getPartiesSubFlowInfo(String caseId) {
        List<PartiesSubFlowInfoVo> partiesSubFlowInfoList = new ArrayList<>();

        Map<String, CasePartiesInfoVo> partyInfoMap = new HashMap<>(10);
        //获取当事人信息
        CasePartiesRecordQueryDto queryDto = new CasePartiesRecordQueryDto();
        queryDto.setCaseId(caseId);
        List<CasePartiesInfoVo> list = casePartiesRecordService.getCasePartiesInfoList(queryDto);
        list.forEach(e -> {
            partyInfoMap.put(e.getPartyId(), e);
        });

        CaseMainDetailAuxiliaryInfoRequest request = new CaseMainDetailAuxiliaryInfoRequest();
        request.setCaseId(caseId);
        List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfoList = caseMainDetailAuxiliaryInfoService.getCaseMainDetailAuxiliaryInfo(request);
        Map<String, CaseMainDetailAuxiliaryInfo> partyCaseMainInfoMap = new HashMap<>(10);
        caseMainDetailAuxiliaryInfoList.forEach(e -> {
            partyCaseMainInfoMap.put(e.getPartyId(), e);
        });
        CaseMainInfoVo caseMainInfoVo = caseMainInfoMapper.selectCaseMainInfo(caseId);
        SysDepartParam sysDepartParam = sysDepartParamService.getSysDepartParamByOrgCodeAndDeptCode(caseMainInfoVo.getCaseOrgCode(), caseMainInfoVo.getCaseDeptCode());
        String isLateFee = sysDepartParam.getIsLateFee();
        List<WorkFlowRollSubMainInfo> workFlowRollSubMainInfoList = workFlowRollSubMainInfoService.getWorkFlowRollSubMainInfoList(caseId);
        workFlowRollSubMainInfoList.forEach(e -> {
            PartiesSubFlowInfoVo partiesSubFlowInfo = new PartiesSubFlowInfoVo();
            partiesSubFlowInfo.setId(e.getId());
            String partyId = e.getWorkSubId();
            partiesSubFlowInfo.setPartyId(partyId);
            //根据当事人id获取当事人信息
            CasePartiesInfoVo partyInfo = partyInfoMap.get(partyId);
            if (ObjectUtils.isEmpty(partyInfo)) {
                log.error("未匹配到当事人案件信息：partyId" + partyId);
            }
            partiesSubFlowInfo.setPartyType(partyInfo.getPartyType());
            partiesSubFlowInfo.setPartyTypeName(PartyTypeEnum.getValueByCode(partyInfo.getPartyType()));
            partiesSubFlowInfo.setPartyName(partyInfo.getPartyName());
            partiesSubFlowInfo.setEntType(partyInfo.getEntType());
            partiesSubFlowInfo.setEntType(partyInfo.getEntTypeName());
            partiesSubFlowInfo.setEntType("委托人姓名");
            partiesSubFlowInfo.setBranchStageCode(e.getWorkCurrentStageCode());
            partiesSubFlowInfo.setBranchStageName(e.getWorkCurrentStageName());
            String linkCode = e.getWorkCurrentLinkCode();
            partiesSubFlowInfo.setBranchLinkCode(e.getWorkCurrentLinkCode());
            partiesSubFlowInfo.setBranchLinkName(e.getWorkCurrentLinkName());
            //设置委托人姓名
            Example documentAuthedEntrust = new Example(CaseDocumentAuthedEntrust.class);
            documentAuthedEntrust.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", partyId).andEqualTo("status", Constant.INTEGER_1);
            List<CaseDocumentAuthedEntrust> caseDocumentAuthedEntrusts = caseDocumentAuthedEntrustMapper.selectByExample(documentAuthedEntrust);
            if (!ObjectUtils.isEmpty(caseDocumentAuthedEntrusts)) {
                partiesSubFlowInfo.setConsignorName(caseDocumentAuthedEntrusts.get(0).getAuthedName());
                //CaseMainInfoVo caseMainInfoVo = caseMainInfoService.getCaseMainInfo(caseId);
                CaseDocumentRecord caseDocumentRecord = new CaseDocumentRecord();
                String docmentCatalogCode = "";
                String kindCode = "SQWTS";
                List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentKindCode(caseId, caseMainInfoVo, kindCode);
                if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
                    docmentCatalogCode = configBusiParamDocumentInfos.get(0).getDocumentCatalogCode();
                    if (Constant.STRING_2.equals(caseMainInfoVo.getHandleType())) {
                        caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, docmentCatalogCode, partyId);
                    } else {
                        caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, docmentCatalogCode);
                    }
                }
                if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
                    partiesSubFlowInfo.setAuthedFileUrl(caseDocumentRecord.getDocumentUrl());
                }
            }
            //查询案件详情补充表
            CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = partyCaseMainInfoMap.get(partyId);
            if (!ObjectUtils.isEmpty(caseMainDetailAuxiliaryInfo)) {
                partiesSubFlowInfo.setPunishExplanation(caseMainDetailAuxiliaryInfo.getPunishContent());
            }
            //可操作的按钮信息（key-按钮名称/value-按钮配置的关键信息）
            String workFlowCode = e.getWorkFlowCode();
            String workFlowVersion = e.getWorkFlowVersion();
            List<ConfigWorkFlowLinkoperateDetailInfo> configWorkFlowLinkoperateDetailInfoList
                    = configWorkFlowLinkoperateDetailInfoService.getConfigWorkFlowLinkoperateDetailInfoByLinkCode(workFlowCode, workFlowVersion, linkCode);
            List<OperateButtonInfoVo> operateButtonInfoVos = new ArrayList<>();
            UserDTO userDTO = UserUtil.getUserInfo();
            List<String> roleIdList = userRoleFeignApi.getRoleIdList(userDTO.getUserId().toString(), userDTO.getOrgCode());
            for (ConfigWorkFlowLinkoperateDetailInfo configWorkFlowLinkoperateDetailInfo : configWorkFlowLinkoperateDetailInfoList) {
                boolean roleRight = false;
                if (roleIdList.contains(configWorkFlowLinkoperateDetailInfo.getOperateAuthRole())) {
                    roleRight = true;
                }
                if (roleRight) {
                    OperateButtonInfoVo operateButtonInfoVo = new OperateButtonInfoVo();
                    BeanUtils.copyProperties(configWorkFlowLinkoperateDetailInfo, operateButtonInfoVo);
                    CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
                    //List<String> allRelationDocCatalogCodeList=getALLRelationDocCatalogCodeList(caseMainInfo.getBusiParamId(),configWorkFlowLinkoperateDetailInfo.getFrontSymble());
                    //TODO zheli返回重复了，要改掉后续
                    MachDocumentInfoVo machDocumentInfoVo = getMachDocumentInfo(caseMainInfo.getBusiParamId(), configWorkFlowLinkoperateDetailInfo.getFrontSymble());
                    operateButtonInfoVo.setMachDocumentInfoVo(machDocumentInfoVo);
                    //TODO zheli返回重复了，要改掉后续
                    List<String> allRelationDocCatalogCodeList = new ArrayList<>();
                    String documentKindCode = "";
                    String documentCatalogCode = configWorkFlowLinkoperateDetailInfo.getFrontSymble();
                    if (StringUtils.isNotBlank(documentCatalogCode)) {
                        Example example = new Example(ConfigBusiParamDocumentInfo.class);
                        example.createCriteria().andEqualTo("busiParamId", caseMainInfo.getBusiParamId()).andEqualTo("documentCatalogCode", documentCatalogCode).andEqualTo("isDeleted", "0");
                        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
                        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
                            String allRelationDocCatalogCode = "";
                            ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfos.get(0);
                            documentKindCode = configBusiParamDocumentInfo.getDocumentKindCode();
                            if (StringUtils.isBlank(configBusiParamDocumentInfo.getRelationDocumentCatalogCode())) {
                                allRelationDocCatalogCode = documentCatalogCode;
                            } else {
                                allRelationDocCatalogCode = documentCatalogCode + "," + configBusiParamDocumentInfo.getRelationDocumentCatalogCode();
                            }
                            allRelationDocCatalogCodeList = Arrays.asList(allRelationDocCatalogCode.split(","));
                        }
                        operateButtonInfoVo.setAllRelationDocCatalogCodeList(allRelationDocCatalogCodeList);
                        operateButtonInfoVo.setDocumentKindCode(documentKindCode);
                    }
                    //陈述申辩复核意见书按钮控制处理
                    if (DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode().equals(documentKindCode)) {
                        //判断是否存在陈述申辩笔录
                        //没有陈述申辩笔录, 不显示陈述申辩复核意见书按钮
                        CaseDocumentRecordDto CSSBBLRecord = caseDocumentRecordService.selectCaseDocumentRecordByKindCodeAndPartyId(caseId, DocumentKindEnum.DOC_KIND_DK2CSSBBL.getCode(), partyId);
                        if (ObjectUtil.isEmpty(CSSBBLRecord)) {
                            continue;
                        }
                        //陈述申辩复核意见书只生成一次, 判断是否已经生成,未生成时，可以提供入口，已经生成过了，不再给入口
                        CaseDocumentRecordDto CSSBFHYJSRecord = caseDocumentRecordService.selectCaseDocumentRecordByKindCodeAndPartyId(caseId, DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode(), partyId);
                        if (ObjectUtil.isNotEmpty(CSSBFHYJSRecord)) {
                            continue;
                        }
                    }
                    if (!(Constant.STRING_1.equals(isLateFee) && Constant.STRING_KIND_CODE_JCFKSPB.equals(documentKindCode)) && !(Constant.STRING_1.equals(isLateFee) && Constant.STRING_KIND_CODE_XZJDLXCGS.equals(documentKindCode))) {
                        operateButtonInfoVos.add(operateButtonInfoVo);
                    }
                }
            }
            partiesSubFlowInfo.setOperateButtonInfo(operateButtonInfoVos);
            partiesSubFlowInfo.setCaseId(caseId);
            partiesSubFlowInfoList.add(partiesSubFlowInfo);
        });
        return partiesSubFlowInfoList;
    }


    /**
     * 描述： 查询简易案件详情
     *
     * @return {@link CaseDetailSimpleInfoVo}
     * @author: zhengqiang
     * @date: 2022/6/20
     * @param: queryDto
     **/
    @Override
    public CaseDetailSimpleInfoVo getCaseDetailSimpleInfo(CaseDetailInfoQueryDto queryDto) {
        String caseId = queryDto.getCaseId();
        CaseDetailSimpleInfoVo caseDetailSimpleInfoVo = new CaseDetailSimpleInfoVo();
        CaseMainInfoVo caseMainInfo = new CaseMainInfoVo();
        //案件基础信息
        try {
            caseMainInfo = getCaseMainInfo(caseId);
        } catch (Exception e) {
            if ("未找到案件信息".equals(e.getMessage())) {
                Example query = new Example(CaseMainInfo.class);
                Example.Criteria c = query.createCriteria();
                c.andEqualTo("dataSourceServiceId", caseId);
                c.andIsNotNull("dataSource");
                List<CaseMainInfo> caseMainInfoList = caseMainInfoMapper.selectByExample(query);
                if (!ObjectUtils.isEmpty(caseMainInfoList) && caseMainInfoList.size() > 0) {
                    CaseMainInfo caseInfo = caseMainInfoList.get(Constant.INTEGER_0);
                    if (!ObjectUtils.isEmpty(caseInfo)) {
                        BeanUtils.copyProperties(caseInfo, caseMainInfo);
                        caseId = caseInfo.getId();
                    }
                } else {
                    throw new BusinessException("未找到案件信息");
                }
            }
        }
        caseDetailSimpleInfoVo.setDataSourceServiceId(caseMainInfo.getDataSourceServiceId());
        caseDetailSimpleInfoVo.setCaseName(caseMainInfo.getCaseName());
        caseDetailSimpleInfoVo.setCaseOrgCode(caseMainInfo.getCaseOrgCode());
        caseDetailSimpleInfoVo.setCaseOrgName(caseMainInfo.getCaseOrgName());
        caseDetailSimpleInfoVo.setCaseId(caseId);
        caseDetailSimpleInfoVo.setCaseSource(caseMainInfo.getCaseSource());
        caseDetailSimpleInfoVo.setCaseStageCode(caseMainInfo.getCaseCurrentStageCode());
        caseDetailSimpleInfoVo.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
        caseDetailSimpleInfoVo.setCaseStatus(caseMainInfo.getCaseStatus());
        //处罚决定时间
        caseDetailSimpleInfoVo.setCaseVerdictEndTime(caseMainInfo.getCaseVerdictEndTime());
        //查询简易案件详情信息
        CaseMainDetailSimpleInfo simpleInfo = caseMainDetailSimpleInfoService.getCaseMainDetailSimpleInfo(caseId);
        if (!ObjectUtils.isEmpty(simpleInfo)) {
            BeanUtils.copyProperties(simpleInfo, caseDetailSimpleInfoVo);
        } else {
            throw new BusinessException("未找到简易案件信息");
        }
        caseDetailSimpleInfoVo.setCaseNumber(simpleInfo.getPunishDocumentNumber());
        caseDetailSimpleInfoVo.setCaseReasonShowName(simpleInfo.getCaseReason());
        //执行情况
        caseDetailSimpleInfoVo.setExecuteWay(simpleInfo.getExecuteWay());
        caseDetailSimpleInfoVo.setExecuteConditionDesc(simpleInfo.getExecuteConditionDesc());
        caseDetailSimpleInfoVo.setExecuteFinishDate(simpleInfo.getExecuteFinishDate());
        //执行情况附件
        CaseAttachmentInfoQueryDto executeFinishAppendixQueryDto = new CaseAttachmentInfoQueryDto();
        executeFinishAppendixQueryDto.setCaseId(caseId);
        executeFinishAppendixQueryDto.setAttachmentTypeId(AttachmentTypeEnum.SIMPLE_CASE_ATTACHMENT_01.getCode());
        List<CaseAttachmentInfoVo> executeFinishAppendixList = caseAppendixRecordService.getCaseAttachmentList(executeFinishAppendixQueryDto);
        caseDetailSimpleInfoVo.setExecuteFinishAppendixList(executeFinishAppendixList);
        caseDetailSimpleInfoVo.setRecallReasonDesc(simpleInfo.getRecallReasonDesc());
        //案由编码获取
        List<CaseReasonMainRecordVo> caseReasonMainRecords = caseReasonMainRecordService.getCaseReasonRecordListByCaseId(caseId);
        //简易处罚涉及只涉及到单案由  (适应人设判空)
        if (ObjectUtil.isNotEmpty(caseReasonMainRecords) && caseReasonMainRecords.size() > 0) {
            CaseReasonMainRecordVo caseReasonMainRecord = caseReasonMainRecords.get(Constant.INTEGER_0);
            caseDetailSimpleInfoVo.setCaseReasonCode(caseReasonMainRecord.getCaseReasonCode());
            //案由领域编码
            caseDetailSimpleInfoVo.setTerritoryCode(caseReasonMainRecord.getTerritoryCode());
            caseDetailSimpleInfoVo.setIllegalBasis(caseReasonMainRecord.getIllegalBasis());
            caseDetailSimpleInfoVo.setIllegalDetail(caseReasonMainRecord.getIllegalDetail());
            caseDetailSimpleInfoVo.setPunishBasis(caseReasonMainRecord.getPunishBasis());
            caseDetailSimpleInfoVo.setPunishDetail(caseReasonMainRecord.getPunishDetail());
        }
        caseDetailSimpleInfoVo.setCaseHappenAddressLocationInfo(simpleInfo.getAddressLatLongitude());
        //违则罚则
        caseDetailSimpleInfoVo.setIllegalFact(simpleInfo.getIllegalFact());
        //案发时间
        caseDetailSimpleInfoVo.setCaseHappenTime(simpleInfo.getCaseHappenTime());
        //违法事实
        caseDetailSimpleInfoVo.setIllegalFact(simpleInfo.getIllegalFact());
        //取证时间--移动端使用
        caseDetailSimpleInfoVo.setCaseHappenTimeStr(simpleInfo.getCaseHappenTime());
        caseDetailSimpleInfoVo.setCaseHappenAddressDetail(simpleInfo.getCaseHappenAddressDetail());
        caseDetailSimpleInfoVo.setCaseReactionContent(simpleInfo.getCaseReactionContent());
        caseDetailSimpleInfoVo.setCaseRemark(simpleInfo.getCaseRemark());
        //处罚内容
        if (simpleInfo.getPunishKinds().contains("罚款")) {
            caseDetailSimpleInfoVo.setPunishContent("罚款" + simpleInfo.getDraftPunishMoney() + "元");

            if (simpleInfo.getPunishKinds().contains("警告")) {
                caseDetailSimpleInfoVo.setPunishContent("警告并罚款" + simpleInfo.getDraftPunishMoney() + "元");
            }

            //若时当场收缴的标记为“当场收缴”；自行缴纳的，自动调用统一公共支付平台接口获取是否缴纳，已缴纳的标记为“自行缴纳”，未缴纳的标记为“未缴纳”
            //缴费结果
            if (PayWayEnum.OFF_SITE.getCode().equals(simpleInfo.getPayWay())) {
                // 结案状态，如果已执行完毕，则执行结果为：自行缴纳
                String caseStatus = caseMainInfo.getCaseStatus();
                if (CaseStatusEnum.END_CASE.getCode().equals(caseStatus)
                        && ObjectUtil.isNotEmpty(simpleInfo.getExecuteFinishDate())) {
                    caseDetailSimpleInfoVo.setPayResult("自行缴纳");
                } else {
                    //自行缴纳，查询缴纳结果
                    try {
                        CasePaymentResultRecordVo resultRecordVo = casePaymentResultRecordService.getCasePaymentResultRecordDetailByCaseId(caseId);
                        caseDetailSimpleInfoVo.setPayResult("自行缴纳");
                        casePaymentResultRecordService.updateSimpleCaseStatusByHistoryPaymentRecord(caseMainInfo, resultRecordVo);
                    } catch (Exception e) {
                        //未缴纳
                        caseDetailSimpleInfoVo.setPayResult("未缴纳");
                    }
                }
            } else {
                caseDetailSimpleInfoVo.setPayResult("当场收缴");
            }

        } else {
            caseDetailSimpleInfoVo.setPunishContent(simpleInfo.getPunishKinds());
        }

        //取证照片列表
        CaseAttachmentInfoQueryDto attachmentInfoQueryDto = new CaseAttachmentInfoQueryDto();
        attachmentInfoQueryDto.setCaseId(caseId);
        attachmentInfoQueryDto.setAttachmentTypeId(AttachmentTypeEnum.EVIDENCE_PHOTO.getCode());
        List<CaseAttachmentInfoVo> caseAttachmentInfoList = caseAppendixRecordService.getCaseAttachmentList(attachmentInfoQueryDto);
        List<CaseEvidencePhotoSimpleVo> caseEvidencePhotoList = new ArrayList<>();
        caseAttachmentInfoList.forEach(e -> {
            CaseEvidencePhotoSimpleVo caseEvidencePhotoSimpleVo = new CaseEvidencePhotoSimpleVo();
            caseEvidencePhotoSimpleVo.setFileKey(e.getId());
            caseEvidencePhotoSimpleVo.setFileUrl(e.getAppendixUrl());
            caseEvidencePhotoSimpleVo.setFileName(e.getAppendixName());
            caseEvidencePhotoList.add(caseEvidencePhotoSimpleVo);
        });
        caseDetailSimpleInfoVo.setCaseEvidencePhotoList(caseEvidencePhotoList);

        //处罚决定书地址
        String finalCaseId = caseId;
        List<CaseDocumentRecordDto> documentRecords = caseDocumentRecordService.getCaseDocumentRecordList(caseId, "");
        if (!ObjectUtils.isEmpty(documentRecords) && documentRecords.size() > 0) {
            CaseMainInfoVo finalCaseMainInfo = caseMainInfo;

            documentRecords.forEach(e -> {
                String documentCatalogCode = e.getDocumentCatalogCode();
                //根据文书目录编码获取文书种类进行校验
                List<ConfigBusiParamDocumentInfo> configList = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentCatalogCode(finalCaseId, finalCaseMainInfo, documentCatalogCode);
                String kindCode;
                if (!ObjectUtils.isEmpty(configList)) {
                    kindCode = configList.get(Constant.INTEGER_0).getDocumentKindCode();
                } else {
                    throw new BusinessException("未匹配文书种类编码信息-caseId:" + finalCaseId + ",documentCatalogCode:" + documentCatalogCode);
                }
                if (Constant.STRING_KIND_CODE_JYCXCFJDS.equals(kindCode)) {
                    String documentUrl = e.getDocumentUrl();
                    String documentUrlAfterSeal = e.getDocumentUrlAfterSeal();
                    //String documentUrlAfterSign = e.getDocumentUrlAfterSign();
                    //优先取签章地址
                    String punishDocumentUrl = ObjectUtils.isEmpty(documentUrlAfterSeal) ? documentUrl : documentUrlAfterSeal;
                    caseDetailSimpleInfoVo.setPunishDocumentUrl(punishDocumentUrl);
                    // 决定书文书模板版本
                    caseDetailSimpleInfoVo.setPunishDocumentTemplateVersion("1");
                    List<String> oldDocumentTemplateCodeList = Arrays.asList("DT2A0223300JYCXCFJDS0000001", "DT2A0283300JYCXCFJDS0000001", "TMPJYCXCFJDS");
                    if (oldDocumentTemplateCodeList.contains(e.getDocumentTemplateCode())) {
                        caseDetailSimpleInfoVo.setPunishDocumentTemplateVersion(Constant.STRING_0);
                    }
                    return;
                }
            });
        }
        //当事人详情
        CasePartiesRecordQueryDto partiesRecordQueryDto = new CasePartiesRecordQueryDto();
        partiesRecordQueryDto.setCaseId(caseId);
        partiesRecordQueryDto.setIsApp(YesOrNoEnum.YES.getCode());
        List<CasePartiesInfoVo> list = casePartiesRecordService.getCasePartiesInfoList(partiesRecordQueryDto);
        CasePartiesInfoVo casePartiesInfoVo = list.get(0);
        caseDetailSimpleInfoVo.setCasePartiesInfoVo(casePartiesInfoVo);

        //判断是否存在法定代表人证件信息缺失情况
        List<CasePartiesLegalInfoVo> loseLegalCertInfoList = casePartiesLegalInfoService.getLegalInfoWhoLoseLegalCertInfo(caseId);
        String isLoseLegalCertInfoCode = YesOrNoEnum.NO.getCode();
        if (!ObjectUtils.isEmpty(loseLegalCertInfoList) && loseLegalCertInfoList.size() > 0) {
            isLoseLegalCertInfoCode = YesOrNoEnum.YES.getCode();
        }
        caseDetailSimpleInfoVo.setIsLoseLegalCertInfoCode(isLoseLegalCertInfoCode);
        caseDetailSimpleInfoVo.setIsLoseLegalCertInfoName(YesOrNoEnum.getValueByCode(isLoseLegalCertInfoCode));

        //办案人员列表
        List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
        caseDetailSimpleInfoVo.setCaseHandlePersonList(caseHandlePersonRecordList);
        AtomicBoolean isCaseHandlerTemp = new AtomicBoolean(false);
        caseDetailSimpleInfoVo.setIsCaseHandler(YesOrNoEnum.NO.getCode());
        caseDetailSimpleInfoVo.setIsCaseHandlerName(YesOrNoEnum.NO.getDes());
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            throw new BusinessException("登录失效");
        }
        Long userId = userInfo.getUserId();
        if (!ObjectUtils.isEmpty(caseHandlePersonRecordList) && caseHandlePersonRecordList.size() > 0) {
            caseHandlePersonRecordList.forEach(e -> {
                if (HandlePersonTypeEnum.MAIN.getCode().equals(e.getHandlePersonType())
                        && ObjectUtils.isEmpty(caseDetailSimpleInfoVo.getCaseHandlingDeptInfo())) {
                    String caseHandlingDeptInfo = e.getHandleOrgName() + "/" + e.getHandleDeptName();
                    //办案部门
                    caseDetailSimpleInfoVo.setCaseHandlingDeptInfo(caseHandlingDeptInfo);
                }
                if (userId.equals(Long.valueOf(e.getHandlePersonId())) && !isCaseHandlerTemp.get()) {
                    isCaseHandlerTemp.set(true);
                    caseDetailSimpleInfoVo.setIsCaseHandler(YesOrNoEnum.YES.getCode());
                    caseDetailSimpleInfoVo.setIsCaseHandlerName(YesOrNoEnum.YES.getDes());
                }
            });
        }

        //文书列表
        //获取案件关联文书
        CaseStageLinkRelateDocumentQueryDto query = new CaseStageLinkRelateDocumentQueryDto();
        query.setCaseId(caseId);
        List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList
                = caseDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
        //案件文书
        List<CaseStageLinkRelateDocumentVo> caseDetailDocInfoList = new ArrayList<>();
        //补正/更正文书列表文书列表
        List<CaseStageLinkRelateDocumentVo> finalReplenishAmendDocumentList = new ArrayList<>();
        //默认未电子送达成功
        caseDetailSimpleInfoVo.setIsElecSendSucc(YesOrNoEnum.NO.getCode());
        List<String> caseStageCodeList = Arrays.asList(CaseStageEnum.PUNISH_EXECUTION.getCode(), CaseStageEnum.CLOSE_ARCHIVING.getCode());
        String caseCurrentStageCode = caseMainInfo.getCaseCurrentStageCode();

        caseStageLinkRelateDocumentList.forEach(e -> {
            // 简易程序允许重制的文书，在案件处于处罚执行阶段，案件结案时 可以补正更正
            if (ShowEditButtonTypeEnum.ALLOW_REMAKE.getCode().equals(e.getIsAllowEdit())
                    && caseStageCodeList.contains(caseCurrentStageCode)) {
                e.setShowEditButtonType(ShowEditButtonTypeEnum.ALLOW_CORRECTION.getCode());
            }
            //补正/更正文书列表文书单独处理
            if (DocumentKindEnum.DOC_KIND_DK2BZGZTZS.getCode().equals(e.getDocumentKindCode())) {
                finalReplenishAmendDocumentList.add(e);
            } else {
                caseDetailDocInfoList.add(e);
            }
            //电子送达信息 --移动端使用
            List<DocumentSendRecordByPartiesVo> documentSendRecordByPartiesVos = documentSendRecordMapper.selectDocumentSendRecordListByPartiesOfPartPunish(finalCaseId, e.getDocumentCatalogCode());
            if (ObjectUtils.isEmpty(documentSendRecordByPartiesVos)) {
                return;
            }
            DocumentSendRecordByPartiesVo documentSendRecordByPartiesVo = documentSendRecordByPartiesVos.get(0);
            if (DocumentSendStatusEnum.SEND_SUCCESS.getCode().equals(documentSendRecordByPartiesVo.getSendStatusId())) {
                //存在送达成功的电子送到记录，设置电子送达信息
                caseDetailSimpleInfoVo.setIsElecSendSucc(YesOrNoEnum.YES.getCode());
                caseDetailSimpleInfoVo.setSentWayInfo(documentSendRecordByPartiesVo.getSendDesc());
                caseDetailSimpleInfoVo.setSentTime(documentSendRecordByPartiesVo.getSentTime());
            }
        });
        //添加缴款电子发票
        try {
            CasePaymentResultRecordVo casePaymentResultRecord = casePaymentResultRecordService.getCasePaymentResultRecordDetailByCaseId(caseId);
            //非空
            String invoiceAddress = casePaymentResultRecord.getElectricInvoiceAddress();
            CaseAttachmentInfoVo caseAttachmentInfoVo = new CaseAttachmentInfoVo();
            if (!ObjectUtils.isEmpty(invoiceAddress)) {
                CaseStageLinkRelateDocumentVo caseStageLinkRelateDocument = new CaseStageLinkRelateDocumentVo();
                caseStageLinkRelateDocument.setDocumentUrl(invoiceAddress);
                String showName = "电子发票（" + casePartiesInfoVo.getPartyName() + "）";
                caseStageLinkRelateDocument.setDocumentCatalogName(showName);
                caseStageLinkRelateDocument.setCreateUserName("系统");
                caseStageLinkRelateDocument.setDocumentCreateTime(casePaymentResultRecord.getCreateTime());
                caseDetailDocInfoList.add(caseStageLinkRelateDocument);
                //执行情况附件
                caseAttachmentInfoVo.setAppendixName(showName);
                caseAttachmentInfoVo.setAppendixUrl(invoiceAddress);
            }
            executeFinishAppendixList.add(caseAttachmentInfoVo);
            caseDetailSimpleInfoVo.setExecuteFinishAppendixList(executeFinishAppendixList);
        } catch (Exception e) {
            e.printStackTrace();
            log.warn(e.getMessage());
        }
        caseDetailSimpleInfoVo.setCaseDetailDocInfoList(caseDetailDocInfoList);
        if (finalReplenishAmendDocumentList.size() > 0) {
            List<CaseStageLinkRelateDocumentVo> replenishAmendDocumentList = finalReplenishAmendDocumentList.stream().sorted(Comparator.comparing(CaseStageLinkRelateDocumentVo::getDocumentCreateTime).reversed()).collect(Collectors.toList());
            caseDetailSimpleInfoVo.setReplenishAmendDocumentList(replenishAmendDocumentList);
        }

        //新增轻微违法处罚结论
        caseDetailSimpleInfoVo.setIsSlightIllegal(simpleInfo.getIsSlightIllegal());
        caseDetailSimpleInfoVo.setInvestConclusion(simpleInfo.getInvestConclusion());
        caseDetailSimpleInfoVo.setNotGivePunishReason(simpleInfo.getNotGivePunishReason());
        //处理委托执法信息
        dealEntrustCaseInfo(caseDetailSimpleInfoVo, simpleInfo);
        return caseDetailSimpleInfoVo;
    }

    /**
     * 处理委托执法信息
     *
     * @param vo
     */
    private void dealEntrustCaseInfo(CaseDetailSimpleInfoVo vo, CaseMainDetailSimpleInfo simpleInfo) {
        //查询案由案件记录
        CaseReasonMainRecord caseRecord = new CaseReasonMainRecord();
        caseRecord.setCaseId(vo.getCaseId());
        //找到委托案件 4->委托案件
        caseRecord.setSxType("4");
        List<CaseReasonMainRecord> records = caseReasonMainRecordMapper.select(caseRecord);
        if (CollUtil.isEmpty(records)) {
            return;
        }
        // 是公安委托执法
        records.stream().filter(r -> Objects.equals(r.getIsPublicSecurity(), Constant.STRING_1))
                .findFirst().ifPresent(r -> {
                    vo.setIsPublicSecurity(true);
                    vo.setTrafficInformationVo(new TrafficInformationVo(simpleInfo));
                });
        //存在委托事项
        vo.setHadEntrustCase(true);
        vo.setEntrustReasonList(records.stream().map(CaseReasonEntrustVo::new).collect(Collectors.toList()));
    }


    /**
     * 【V1.3.0】描述：案件撤回某个处置环节操作
     *
     * @param caseId 案件id,caseLinkCode 环节编码
     * @author tianrunjia
     * @date 2022-06-24
     */
    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public void doRecallCaseHandleLink(String caseId, String caseLinkCode) {
        //案件状态为处罚决定撤销时，无法进行环节撤回操作
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        if (caseMainInfoService.validateCaseIsInNotDealStatus(caseMainInfo, null)) {
            throw new BusinessException("当前案件状态不允许进行该操作");
        }
        workFlowRollMainInfoService.doRecallWorkFlowLink(caseId, caseLinkCode);
        String userId = "";
        UserDTO userInfo = UserUtil.getUserInfo();
        if (userInfo != null) {
            userId = String.valueOf(userInfo.getUserId());
        }
        //生成一条撤回记录，然后定时上报删除当前阶段以及后面阶段已经上报成功的数据
        caseDataChangeReportRecordService.save(caseId, CaseChangeOperationTypeEnum.OPERATION_TYPE_5.getCode(), userId);
        // 撤回后，将原本案件的裁决完毕日期置空
        CaseMainInfo caseMainInfoNow = caseMainInfoMapper.selectByPrimaryKey(caseId);
        if (ObjectUtil.isNotNull(caseMainInfoNow)) {
            if (caseMainInfoNow.getCaseVerdictEndTime()!=null) {
                caseMainInfoNow.setCaseVerdictEndTime(null);
                caseMainInfoMapper.updateByPrimaryKey(caseMainInfoNow);
            }
        }
    }

    /**
     * 【V1.11.3】描述： 退回调查取证
     *
     * @return
     * @author: zhengqiang
     * @date: 2023/4/10
     * @param: caseId
     **/
    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public void doRecallToInvestigation(String caseId) {
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        if (caseMainInfoService.validateCaseIsInNotDealStatus(caseMainInfo, null)) {
            throw new BusinessException("当前案件状态不允许进行该操作");
        }
        //撤回到调查取证阶段
        String flowCode = caseMainInfo.getCaseFlowCode();
        String flowVersion = caseMainInfo.getCaseFlowVersion();
        String caseLinkCode = "";
        Example example = new Example(ConfigWorkFlowDetailInfo.class);
        example.createCriteria().andEqualTo("workFlowCode", flowCode).andEqualTo("workFlowVersion", flowVersion)
                .andEqualTo("workStageCode", "INVESTIGATION");
        example.orderBy("workLinkCode").asc();
        List<ConfigWorkFlowDetailInfo> configWorkFlowDetailInfos = configWorkFlowDetailInfoMapper.selectByExample(example);
        if (ObjectUtil.isNotEmpty(configWorkFlowDetailInfos)) {
            caseLinkCode = configWorkFlowDetailInfos.get(0).getWorkLinkCode();
        }
        caseMainInfoService.doRecallCaseHandleLink(caseId, caseLinkCode);
    }

    /**
     * 根据案件阶段获取对应文书
     *
     * @param queryDto
     * @return {@link CaseStageDocumentInfoVo}
     * @author liyafeng
     * @date 2022/8/3
     */
    @Override
    public List<CaseStageDocumentInfoVo> getCaseStageDocumentInfo(CaseStageDocumentQueryDto queryDto) {
        List<CaseStageDocumentInfoVo> voList = new ArrayList<>();
        CaseMainInfoVo caseMainInfoVo = caseMainInfoService.getCaseMainInfo(queryDto.getCaseId());
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(queryDto.getCaseId());
        //如果为案源案件 需展示案源相关文书
        if (ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfoVo.getDataSource())) {
            CaseStageDocumentInfoVo caseStageDocumentInfoVo = new CaseStageDocumentInfoVo();
            caseStageDocumentInfoVo.setCaseCurrentLinkName(caseMainInfoVo.getCaseCurrentLinkName());
            caseStageDocumentInfoVo.setCaseCurrentLinkCode(caseMainInfoVo.getCaseCurrentLinkCode());
            caseStageDocumentInfoVo.setCaseStageName(Constant.CASE_SOURCE_STAGE_NAME);
            caseStageDocumentInfoVo.setCaseStageCode(Constant.CASE_SOURCE_STAGE_CODE);
            if (Constant.STRING_1.equals(queryDto.getDocType())) {
                /*List<CaseStageLinkRelateDocumentVo>  caseStageLinkRelateDocumentVos=new ArrayList<>();
                Example example=new Example(CaseSourceDocumentRecord.class);
                example.createCriteria().andEqualTo("caseSourceId",queryDto.getCaseId()).andEqualTo("documentRecordStatus",Constant.STRING_1);
                List<CaseSourceDocumentRecord> caseSourceDocumentRecords=caseSourceDocumentRecordMapper.selectByExample(example);
                caseSourceDocumentRecords.forEach(caseSourceDocumentRecord -> {
                    CaseStageLinkRelateDocumentVo vo=new CaseStageLinkRelateDocumentVo();
                    BeanUtils.copyProperties(caseSourceDocumentRecord,vo);
                    ConfigBusiParamDocumentInfo configBusiParamDocumentInfo=configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(caseSourceDocumentRecord.getDocumentCatalogCode());
                    vo.setDocumentCatalogName(configBusiParamDocumentInfo.getDocumentKindName());
                    if (com.icinfo.framework.tools.utils.StringUtils.isNotEmpty(caseSourceDocumentRecord.getDocumentUrlAfterSeal())) {
                        vo.setDocumentUrl(caseSourceDocumentRecord.getDocumentUrlAfterSeal());
                    }
                    if (com.icinfo.framework.tools.utils.StringUtils.isNotEmpty(caseSourceDocumentRecord.getDocumentUrlAfterSign())) {
                        vo.setDocumentUrl(caseSourceDocumentRecord.getDocumentUrlAfterSign());
                    }
                    vo.setDocumentCreateTime(caseSourceDocumentRecord.getDocumentCreateTime());
                    vo.setIsOnlyDetail(Constant.STRING_1);
                    caseStageLinkRelateDocumentVos.add(vo);
                });*/
                Example partyExample = new Example(CaseSourcePartyInfo.class);
                partyExample.createCriteria().andEqualTo("caseSourceId", caseMainInfoVo.getId()).andEqualTo("status", Constant.STRING_1);
                List<CaseSourcePartyInfo> caseSourcePartyInfos = caseSourcePartyInfoMapper.selectByExample(partyExample);
                //文书列表
                CaseSourceLinkRelateDocumentQueryDto query = new CaseSourceLinkRelateDocumentQueryDto();
                query.setCaseSourceId(caseMainInfoVo.getId());
                query.setDocumentRecordStatus(Constant.STRING_1);
                List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList = caseSourceDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
                for (CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo : caseStageLinkRelateDocumentList) {
                    caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                    //多当事人并且文书针对人
                    if (Constant.STRING_2.equals(caseStageLinkRelateDocumentVo.getDocumentLinkObjectType()) && caseSourcePartyInfos.size() > 1) {
                        String partyId = caseStageLinkRelateDocumentVo.getPartyId();
                        String[] partyIdArr = partyId.split(",");
                        if (partyIdArr.length == 1) {
                            CaseSourcePartyInfo caseSourcePartyInfo = caseSourcePartyInfoMapper.selectByPrimaryKey(partyId);
                            if (null != caseSourcePartyInfo) {
                                String documentCatalogName = caseStageLinkRelateDocumentVo.getDocumentCatalogName() + "(" + caseSourcePartyInfo.getPartyName() + ")";
                                caseStageLinkRelateDocumentVo.setDocumentCatalogName(documentCatalogName);
                            }
                        }
                    }
                    //文书修改设置
                    if (YesOrNoEnum.YES.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit())
                            && "FLOW-202207280305".equals(caseMainInfoVo.getCaseFlowCode())) {
                        //todo 先写死全省工作流的案件才能修改文书, 后续优化
                        caseStageLinkRelateDocumentVo.setShowEditButtonType(caseStageLinkRelateDocumentVo.getIsAllowEdit());
                    }
                }
                //案源附件查询
                Example materialExample = new Example(CaseSourceMaterialRecord.class);
                materialExample.createCriteria().andEqualTo("caseSourceId", queryDto.getCaseId()).andEqualTo("isDelete", Constant.STRING_0);
                List<CaseSourceMaterialRecord> caseSourceMaterialRecordList = caseSourceMaterialRecordMapper.selectByExample(materialExample);
                caseSourceMaterialRecordList.forEach(caseSourceMaterialRecord -> {
                    CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo = new CaseStageLinkRelateDocumentVo();
                    caseStageLinkRelateDocumentVo.setDocumentUrl(caseSourceMaterialRecord.getMaterialUrl());
                    caseStageLinkRelateDocumentVo.setDocumentId(caseSourceMaterialRecord.getId());
                    caseStageLinkRelateDocumentVo.setDocumentCreateTime(caseSourceMaterialRecord.getUploadTime());
                    caseStageLinkRelateDocumentVo.setCreateUserName(caseSourceMaterialRecord.getUploadUserName());
                    caseStageLinkRelateDocumentVo.setDocumentCatalogName(caseSourceMaterialRecord.getMaterialName());
                    caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                    if (!ObjectUtils.isEmpty(caseSourceMaterialRecord.getEvidenceUid())) {
                        //证据文件
                        caseStageLinkRelateDocumentVo.setIsEvidenceDoc(YesOrNoEnum.YES.getCode());
                    }
                    caseStageLinkRelateDocumentList.add(caseStageLinkRelateDocumentVo);
                });
                Collections.sort(caseStageLinkRelateDocumentList, (o1, o2) -> o1.getDocumentCreateTime().compareTo(o2.getDocumentCreateTime()));
                caseStageDocumentInfoVo.setCaseStageRelateDocumentList(caseStageLinkRelateDocumentList);
            } else {
                caseStageDocumentInfoVo.setCaseStageRelateDocumentList(Collections.EMPTY_LIST);
            }
            voList.add(caseStageDocumentInfoVo);
        }
        //根据工作流版本号、工作流编号查询有配对文书目录编码的文书配置信息
        String workFlowVersion = caseMainInfoVo.getCaseFlowVersion();
        String workFlowCode = caseMainInfoVo.getCaseFlowCode();
        List<ConfigWorkFlowDocument> list =
                configWorkFlowDocumentService.getConfigWorkFlowDocumentMatchedListByFlowCode(workFlowCode, workFlowVersion);
        Map<String, String> matchMapCataLogCode = new HashMap<>(20);
        Map<String, String> matchMapIsMatchDocument = new HashMap<>(20);
        list.forEach(e -> {
            matchMapCataLogCode.put(e.getDocumentCatalogCode(), e.getMatchedDocumentCatalogCode());
            matchMapIsMatchDocument.put(e.getDocumentCatalogCode(), e.getIsMatchDocument());
        });
        String caseId = queryDto.getCaseId();
        //案件阶段查询
        ConfigDictionaryInfoQueryDto dto = new ConfigDictionaryInfoQueryDto();
        dto.setIsEffective(Constant.STRING_1);
        dto.setDicFieldCode(Constant.STRING_CASE_STAGE);
        //案件处理-流程取remark为名称
        if (Constant.STRING_2.equals(caseMainDetailInfoMapper.getHandleConclusionByCaseId(caseId))) {
            dto.setIsRemarkName(Constant.WHETHER_STRING_YES);
        }
        List<ConfigDictionaryInfoVo> configDictionaryInfoVos = configDictionaryInfoService.getConfigDictionaryList(dto);
        //关联文书
        List<CaseStageLinkRelateDocumentVo> relatedDocList = caseRelatedDocumentRecordService.getRelatedDocInfoToCaseStageLinkRelateDocument(caseId);
        //线下上传文书
        List<CaseStageLinkRelateDocumentVo> offlineDocList = caseOfflineDocumentRecordService.getOfflineDocInfoToCaseStageLinkRelateDocument(caseId);


        if (null != configDictionaryInfoVos && configDictionaryInfoVos.size() > 0) {
            for (ConfigDictionaryInfoVo configDictionaryInfoVo : configDictionaryInfoVos) {
                String caseStageCode = configDictionaryInfoVo.getDicCode();
                CaseStageDocumentInfoVo vo = new CaseStageDocumentInfoVo();
                vo.setCaseCurrentLinkName(caseMainInfoVo.getCaseCurrentLinkName());
                vo.setCaseCurrentLinkCode(caseMainInfoVo.getCaseCurrentLinkCode());
                vo.setCaseStageCode(configDictionaryInfoVo.getDicCode());
                vo.setCaseStageName(configDictionaryInfoVo.getDicName());
                CaseStageLinkRelateDocumentQueryDto query = new CaseStageLinkRelateDocumentQueryDto();
                query.setCaseId(queryDto.getCaseId());
                query.setCaseStageCode(configDictionaryInfoVo.getDicCode());
                if (Constant.STRING_1.equals(queryDto.getDocType())) {
                    //查询正常和草稿文书
                    query.setDocumentRecordStatus(Constant.STRING_1_2);
                } else if (Constant.STRING_0.equals(queryDto.getDocType())) {
                    query.setDocumentRecordStatus(Constant.STRING_3);
                }
                List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList
                        = caseDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
                List<CaseStageLinkRelateDocumentVo> filterCaseStageLinkRelateDocumentList = new ArrayList<>();
                for (CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo : caseStageLinkRelateDocumentList) {

                    String caseStatus = caseMainInfoVo.getCaseStatus();

                    //多当事人分别处罚按钮控制需单独处理
                    if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(caseMainInfoVo.getCasePartiesReasonType())
                            && HandleTypeEnum.PART_PUNISH.getCode().equals(caseMainInfoVo.getHandleType())) {
                        List<String> documentKind = Arrays.asList(DocumentKindEnum.DOC_KIND_LASPB.getCode(), DocumentKindEnum.DOC_KIND_ZJBG.getCode());
                        if (!documentKind.contains(caseStageLinkRelateDocumentVo.getDocumentKindCode())) {
                            //允许修改的文书
                            if (DocumentStatusEnum.CHECK_END.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus())
                                    && ShowEditButtonTypeEnum.NOT_EDIT.getCode().equals(caseStageLinkRelateDocumentVo.getShowEditButtonType())
                                    && (YesOrNoEnum.YES.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit())
                                    || ShowEditButtonTypeEnum.ALLOW_REMAKE.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit()))) {
                                //查询是否存在操作中的修改记录
                                List<CaseDocumentModifyRecord> caseDocumentModifyRecordList = caseDocumentModifyRecordService.getCaseDocumentModifyRecordListByOriginalDocumentId(caseId, caseStageLinkRelateDocumentVo.getDocumentId());
                                if (ObjectUtils.isEmpty(caseDocumentModifyRecordList)) {
                                    caseStageLinkRelateDocumentVo.setShowEditButtonType(caseStageLinkRelateDocumentVo.getIsAllowEdit());
                                } else {
                                    CaseDocumentModifyRecord caseDocumentModifyRecord = caseDocumentModifyRecordList.get(0);
                                    Example waitExample = new Example(CaseApprovalWaitRecord.class);
                                    waitExample.createCriteria().andEqualTo("caseId", caseDocumentModifyRecord.getCaseId()).andEqualTo("docId", caseDocumentModifyRecord.getDocumentId());
                                    List<CaseApprovalWaitRecord> currentRecord = caseApprovalWaitRecordMapper.selectByExample(waitExample);
                                    if (ObjectUtils.isEmpty(currentRecord)) {
                                        caseStageLinkRelateDocumentVo.setShowEditButtonType(caseStageLinkRelateDocumentVo.getIsAllowEdit());
                                    }
                                }
                            }
                        }
                    }

                    //送达的文书不可修改或重制
                    if (DocumentStatusEnum.SENT.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentSentStatus())) {
                        caseStageLinkRelateDocumentVo.setShowEditButtonType(ShowEditButtonTypeEnum.NOT_EDIT.getCode());
                    }
                    //如果时已送达，并且isAllowEdit=2时，将IsShowEdit值改为3，即显示补正/更正按钮
                    if (DocumentStatusEnum.SENT.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentSentStatus()) &&
                            ShowEditButtonTypeEnum.ALLOW_REMAKE.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit())) {
                        caseStageLinkRelateDocumentVo.setShowEditButtonType(ShowEditButtonTypeEnum.ALLOW_CORRECTION.getCode());
                    }
                    //todo 多当事人分别处罚，暂时不显示修改、重制、补正/更正按钮按钮，待实现
                    /*if ( PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(caseMainInfoVo.getCasePartiesReasonType())
                            && HandleTypeEnum.PART_PUNISH.getCode().equals(caseMainInfoVo.getHandleType())){
                        List<String> documentKind = Arrays.asList(DocumentKindEnum.DOC_KIND_LASPB.getCode(), DocumentKindEnum.DOC_KIND_ZJBG.getCode());
                        if (!documentKind.contains(caseStageLinkRelateDocumentVo.getDocumentKindCode())){
                            caseStageLinkRelateDocumentVo.setShowEditButtonType(ShowEditButtonTypeEnum.NOT_EDIT.getCode());
                        }
                    }*/
                    if (caseStageLinkRelateDocumentVo.getDocumentKindCode().equals(Constant.STRING_KIND_CODE_SDHZ)) {
                        continue;
                    }
                    String documentKindCode = caseStageLinkRelateDocumentVo.getDocumentKindCode();
                    //根据文书目录编码查询关联文书
                    caseStageLinkRelateDocumentVo.setIsInvalid(Constant.STRING_0);
                    //失效状态文书状态处理
                    if (DocumentRecordStatusEnum.INVALID.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentRecordStatus())) {
                        caseStageLinkRelateDocumentVo.setIsInvalid(Constant.STRING_1);
                    }
                    if (Constant.STRING_KIND_CODE_SQWTS.equals(caseStageLinkRelateDocumentVo.getDocumentKindCode())) {
                        Example documentAuthedEntrust = new Example(CaseDocumentAuthedEntrust.class);
                        documentAuthedEntrust.createCriteria().andEqualTo("caseId", queryDto.getCaseId()).andEqualTo("partyId", caseStageLinkRelateDocumentVo.getPartyId()).andEqualTo("status", Constant.INTEGER_1);
                        List<CaseDocumentAuthedEntrust> caseDocumentAuthedEntrusts = caseDocumentAuthedEntrustMapper.selectByExample(documentAuthedEntrust);
                        if (caseDocumentAuthedEntrusts.isEmpty()) {
                            caseStageLinkRelateDocumentVo.setIsInvalid("1");
                        }
                    }
                    List<String> allRelationDocCatalogCodeList = getALLRelationDocCatalogCodeList(caseMainInfoVo.getBusiParamId(), caseStageLinkRelateDocumentVo.getDocumentCatalogCode());
                    caseStageLinkRelateDocumentVo.setAllRelationDocCatalogCodeList(allRelationDocCatalogCodeList);
                    caseStageLinkRelateDocumentVo.setMatchDocumentCatalogCode(matchMapCataLogCode.get(caseStageLinkRelateDocumentVo.getDocumentCatalogCode()));
                    caseStageLinkRelateDocumentVo.setIsMatchDocument(matchMapIsMatchDocument.get(caseStageLinkRelateDocumentVo.getDocumentCatalogCode()));
                    MachDocumentInfoVo machDocumentInfoVo = getMachDocumentInfo(caseMainInfoVo.getBusiParamId(), caseStageLinkRelateDocumentVo.getDocumentCatalogCode());
                    caseStageLinkRelateDocumentVo.setMachDocumentInfoVo(machDocumentInfoVo);
                    String handleType = caseMainInfoVo.getHandleType();
                    /*if(Constant.STRING_2.equals(handleType)){
                        String partyId=caseStageLinkRelateDocumentVo.getPartyId();
                        String[] partyIdArr=partyId.split(",");
                        if(partyIdArr.length==1){
                            Example example=new Example(CasePartiesRecord.class);
                            example.createCriteria().andEqualTo("partyId",partyId).andEqualTo("status",Constant.STRING_1);
                            List<CasePartiesRecord> casePartiesRecords= casePartiesRecordMapper.selectByExample(example);
                            if(null!=casePartiesRecords&&casePartiesRecords.size()>0){
                                String documentCatalogName=caseStageLinkRelateDocumentVo.getDocumentCatalogName()+"("+casePartiesRecords.get(0).getPartyName()+")";
                                caseStageLinkRelateDocumentVo.setDocumentCatalogName(documentCatalogName);
                            }
                        }
                    }*/
                    //多当事人案件中，文书列表中标题中增加当事人名称展示。示例：电子送达地址确认书（张三）。
                    String casePartiesReasonType = caseMainInfoVo.getCasePartiesReasonType();
                    String partyId = caseStageLinkRelateDocumentVo.getPartyId();
                    if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                            && (!ObjectUtils.isEmpty(partyId) && !partyId.contains(",")) && Constant.STRING_2.equals(caseStageLinkRelateDocumentVo.getDocumentLinkObjectType())) {
                        //多当事人合并处罚不拼接当事人名称
                        //查询当事人名称
                        CasePartiesRecordVo firstPartyInfo = null;
                        List<CasePartiesRecordVo> casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
                        if (!ObjectUtils.isEmpty(partyId)) {
                            for (CasePartiesRecordVo partiesRecord : casePartiesRecordList) {
                                if (partyId.equals(partiesRecord.getPartyId())) {
                                    firstPartyInfo = partiesRecord;
                                    break;
                                }
                            }
                        } else {
                            firstPartyInfo = casePartiesRecordList.get(Constant.INTEGER_0);
                        }
                        if (!ObjectUtils.isEmpty(firstPartyInfo)) {
                            caseStageLinkRelateDocumentVo.setDocumentCatalogName(caseStageLinkRelateDocumentVo.getDocumentCatalogName() + "(" + firstPartyInfo.getPartyName() + ")");
                        }
                    }
                    if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(documentKindCode)) {
                        caseStageLinkRelateDocumentVo.setCaseDocumentTypeFlag(Constant.STRING_1);
                    }
                    // 强制执行显示执行情况
                    if (DocumentKindEnum.DOC_KIND_QZZXSQS.getCode().equals(documentKindCode)) {
                        caseStageLinkRelateDocumentVo.setCaseDocumentTypeFlag(Constant.STRING_2);
                    }
                    //增加处罚决定书是否展示公示详情处理
                    if (Constant.STRING_KIND_CODE_CFJDS.equals(caseStageLinkRelateDocumentVo.getDocumentKindCode())) {
                        //默认展示公示详情按钮
                        caseStageLinkRelateDocumentVo.setIsShowPublicity(YesOrNoEnum.YES.getCode());
                        caseStageLinkRelateDocumentVo.setIsShowPublicityName("展示公示");
                    }

                    //增加失效文书处理
                    addInvalidDocumentRecord(caseStageLinkRelateDocumentVo, caseId, filterCaseStageLinkRelateDocumentList);

                    //增加涉嫌犯罪案件移送记录
                    if (DocumentKindEnum.DOC_KIND_DK2SXFZAJYSS.getCode().equals(documentKindCode)
                            && DocumentStatusEnum.CHECK_END.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus())) {
                        //审批通过且案件状态处于办案中则展示移送按钮
                        /*if (DocumentStatusEnum.CHECK_END.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus())
                                && CaseStatusEnum.HANDLING_CASE.getCode().equals(caseMainInfoVo.getCaseStatus())) {
                            caseStageLinkRelateDocumentVo.setIsShowTransfer(YesOrNoEnum.YES.getCode());
                        }
                        //是否展示移送详情按钮
                        if (DocumentStatusEnum.CHECK_END.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus())
                                && (CaseStatusEnum.HANDLING_CRIMINAL_TRANSFER.getCode().equals(caseMainInfoVo.getCaseStatus())
                                || CaseStatusEnum.END_CRIMINAL_TRANSFER.getCode().equals(caseMainInfoVo.getCaseStatus()))) {
                            caseStageLinkRelateDocumentVo.setIsShowTransferDetail(YesOrNoEnum.YES.getCode());
                        }*/

                        //审批通过才增加移送记录
                        addLawenforceCaseTransferRecord(caseStageLinkRelateDocumentVo, caseId, filterCaseStageLinkRelateDocumentList);
                    }

                    //允许修改的文书,增加文书修改申请记录
                    if (YesOrNoEnum.YES.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit()) || ShowEditButtonTypeEnum.ALLOW_REMAKE.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit())) {
                        addDocumentModifyRecord(caseStageLinkRelateDocumentVo, caseId, filterCaseStageLinkRelateDocumentList);
                    }

                    filterCaseStageLinkRelateDocumentList.add(caseStageLinkRelateDocumentVo);
                    //补正/更正审批表和通知记录ID集合
                    if (DocumentKindEnum.DOC_KIND_DK1BZGZSPB.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentKindCode())) {
                        //补正更正审批表按钮控制单独处理
                        if (DocumentStatusEnum.CHECK_END.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus())
                                && ShowEditButtonTypeEnum.NOT_EDIT.getCode().equals(caseStageLinkRelateDocumentVo.getShowEditButtonType())
                                && YesOrNoEnum.YES.getCode().equals(caseStageLinkRelateDocumentVo.getIsAllowEdit())) {
                            //查询是否存在操作中的修改记录
                            List<CaseDocumentModifyRecord> caseDocumentModifyRecordList = caseDocumentModifyRecordService.getCaseDocumentModifyRecordListByOriginalDocumentId(caseId, caseStageLinkRelateDocumentVo.getDocumentId());
                            if (ObjectUtils.isEmpty(caseDocumentModifyRecordList)) {
                                caseStageLinkRelateDocumentVo.setShowEditButtonType(caseStageLinkRelateDocumentVo.getIsAllowEdit());
                            } else {
                                CaseDocumentModifyRecord caseDocumentModifyRecord = caseDocumentModifyRecordList.get(0);
                                Example waitExample = new Example(CaseApprovalWaitRecord.class);
                                waitExample.createCriteria().andEqualTo("caseId", caseDocumentModifyRecord.getCaseId()).andEqualTo("docId", caseDocumentModifyRecord.getDocumentId());
                                List<CaseApprovalWaitRecord> currentRecord = caseApprovalWaitRecordMapper.selectByExample(waitExample);
                                if (ObjectUtils.isEmpty(currentRecord)) {
                                    caseStageLinkRelateDocumentVo.setShowEditButtonType(caseStageLinkRelateDocumentVo.getIsAllowEdit());
                                }
                            }
                        }
                        CaseDocumentRecord param = new CaseDocumentRecord();
                        param.setRelationApprovalDocumentId(caseStageLinkRelateDocumentVo.getDocumentId());
                        CaseDocumentRecord queryRe = caseDocumentRecordMapper.selectOne(param);
                        if (queryRe != null) {
                            List<String> documentIds = CollUtil.newArrayList();
                            documentIds.add(caseStageLinkRelateDocumentVo.getDocumentId());
                            documentIds.add(queryRe.getId());
                            caseStageLinkRelateDocumentVo.setRelationDocumentIdList(documentIds);
                        }
                    }
                    //如果是立案审批表，并且是速结程序
                    if (DocumentKindEnum.DOC_KIND_LASPB.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentKindCode()) && CaseTypeEnum.SIMPLE_QUICK.getCode().equals(caseMainInfoVo.getCaseType())) {
                        String documentCatalogCodeOfSJGZS = null;
                        try {
                            documentCatalogCodeOfSJGZS = caseDocumentRecordService.getDocumentCatalogCodeOfSJGZS(caseMainInfoVo.getCaseAreaCode(), caseMainInfoVo.getBusiParamId());
                        } catch (Exception exception) {
                            documentCatalogCodeOfSJGZS = null;
                        }
                        //ConfigBusiParamDocumentInfo fastNoticeConfig = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(caseMainInfoVo.getBusiParamId(), DocumentKindEnum.DOC_KIND_DK2SJCXGZS.getCode());
                        if (documentCatalogCodeOfSJGZS != null) {
                            CaseDocumentRecord fastNoticeRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, documentCatalogCodeOfSJGZS);
                            if (fastNoticeRecord != null && DocumentStatusEnum.CONFIRM_END.getCode().equals(fastNoticeRecord.getDocumentSignstampedStatus())) {
                                caseStageLinkRelateDocumentVo.setFastNoticeIsSign(YesOrNoEnum.YES.getCode());
                            } else {
                                caseStageLinkRelateDocumentVo.setFastNoticeIsSign(YesOrNoEnum.NO.getCode());
                            }
                        }
                    }
                    //结案不展示文书修改按钮
                    if (Constant.STRING_3.equals(caseStatus)) {
                        //结案状态的行政处罚（听证类）告知书和行政处罚决定书显示补正/更正，补正/更正审批表显示修改
                        //结案状态的行政处罚（听证类）告知书和行政处罚决定书显示补正/更正，补正/更正审批表显示修改
                        if (!(DocumentKindEnum.DOC_KIND_CFGZSTZL.getCode().equals(documentKindCode) || DocumentKindEnum.DOC_KIND_CFJDS.getCode().equals(documentKindCode) || DocumentKindEnum.DOC_KIND_DK1BZGZSPB.getCode().equals(documentKindCode) || DocumentKindEnum.DOC_KIND_CFGZS.getCode().equals(documentKindCode))) {
                            caseStageLinkRelateDocumentVo.setShowEditButtonType(Constant.STRING_0);
                        }
                        // 结案状态 行政处罚决定审批表 始终展示修改按钮
                        if (DocumentKindEnum.DOC_KIND_CFJDSPB.getCode().equals(documentKindCode)) {
                            caseStageLinkRelateDocumentVo.setShowEditButtonType(Constant.STRING_1);
                        }
                    }
                    // todo 快速办理暂不展示修改按钮

                    if (CaseTypeEnum.FAST_PROCEDURE.getCode().equals(caseMainInfoVo.getCaseType())) {
                        caseStageLinkRelateDocumentVo.setShowEditButtonType(Constant.STRING_0);
                        //违法告知流程且文书处于待提交,显示编辑按钮
                        //简案快办表单状态不是-1的时候展示编辑按钮 （解决撤回后正常流程还显示编辑按钮的问题）
                        if (FAST_CASE_ALLOW_EDIT_KIND_CODE_LIST.contains(documentKindCode)
                                && !Constant.STRING_MINUS_1.equals(caseMainDetailInfo.getSimpleFormType())
                                && (DocumentStatusEnum.WAIT_TO_SUBMIT.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus())
                                || DocumentStatusEnum.CHECK_BACK.getCode().equals(caseStageLinkRelateDocumentVo.getDocumentApprovalStatus()))) {
                            caseStageLinkRelateDocumentVo.setShowEditButtonType(ShowEditButtonTypeEnum.ALLOW_EDIT_FAST_CASE.getCode());
                        }
                        //终结报告编辑按钮控制
                        //违法告知流程且处于处罚告知或不予处罚告知环节,显示编辑按钮
                        //简案快办表单状态不是-1的时候展示编辑按钮 （解决撤回后正常流程还显示编辑按钮的问题）
                        if (DocumentKindEnum.DOC_KIND_ZJBG.getCode().equals(documentKindCode)
                                && !Constant.STRING_MINUS_1.equals(caseMainDetailInfo.getSimpleFormType())
                                && ObjectUtils.isEmpty(caseMainInfoVo.getCaseNumber())
                                && ("处罚告知".equals(caseMainInfoVo.getCaseCurrentLinkName()) || "不予处罚告知".equals(caseMainInfoVo.getCaseCurrentLinkName()))) {
                            caseStageLinkRelateDocumentVo.setShowEditButtonType(ShowEditButtonTypeEnum.ALLOW_EDIT_FAST_CASE.getCode());
                        }
                    }
                }
                //加入关联文书
                if (Constant.STRING_1.equals(queryDto.getDocType())) {
                    if (!ObjectUtils.isEmpty(relatedDocList) && relatedDocList.size() > 0) {
                        relatedDocList.forEach(e -> {
                            e.setCaseDocumentTypeFlag(Constant.STRING_4);
                            if (caseStageCode.equals(e.getCaseStageCode())) {
                                filterCaseStageLinkRelateDocumentList.add(e);
                            }
                        });
                    }
                    //加入线下上传文书
                    if (!ObjectUtils.isEmpty(offlineDocList) && offlineDocList.size() > 0) {
                        offlineDocList.forEach(e -> {
                            e.setCaseDocumentTypeFlag(Constant.STRING_3);
                            if (caseStageCode.equals(e.getCaseStageCode())) {
                                filterCaseStageLinkRelateDocumentList.add(e);
                            }
                        });
                    }
                }

                Collections.sort(filterCaseStageLinkRelateDocumentList, (o1, o2) -> o1.getDocumentCreateTime().compareTo(o2.getDocumentCreateTime()));
                vo.setCaseStageRelateDocumentList(filterCaseStageLinkRelateDocumentList);
                voList.add(vo);
            }
        }
        // 作废文书添加删除的附件
        if (Constant.STRING_0.equals(queryDto.getDocType())) {
            voList.forEach(a -> {
                CaseAppendixQueryDto caseAppendixQueryDto = new CaseAppendixQueryDto();
                caseAppendixQueryDto.setCaseId(queryDto.getCaseId());
                caseAppendixQueryDto.setIsDelete(Constant.STRING_1);
                caseAppendixQueryDto.setCaseStageCode(a.getCaseStageCode());
                List<CaseAttachmentInfoVo> caseAttachmentInfoList = caseAppendixRecordMapper.selectCaseAttachmentSortList(caseAppendixQueryDto);
                a.setCaseAttachmentInfoList(caseAttachmentInfoList);
            });
        }
        //添加案件移交记录
        addCaseTransferRecord(voList, caseId);
        // 电子档案
        if (Constant.STRING_1.equals(queryDto.getDocType())) {
            addEletricArchive(voList, caseId);
        }
        return voList;
    }

    /**
     * 电子档案
     *
     * @param voList
     * @param caseId
     */
    private void addEletricArchive(List<CaseStageDocumentInfoVo> voList, String caseId) {
        CaseElectricArchiveRecord electricArchiveRecordByCaseId = caseElectricArchiveRecordService.getElectricArchiveRecordByCaseId(caseId);
        if (null != electricArchiveRecordByCaseId) {
            CaseStageLinkRelateDocumentVo tempData = new CaseStageLinkRelateDocumentVo();
            tempData.setDocumentCatalogName("电子卷宗");
            tempData.setDocumentUrl(electricArchiveRecordByCaseId.getArchiveUrl());
            tempData.setDocumentKindName("电子卷宗");
            tempData.setCreateUserName(Optional.ofNullable(electricArchiveRecordByCaseId.getUpdateUserName()).orElse(electricArchiveRecordByCaseId.getCreateUserName()));
            tempData.setDocumentCreateTime(Optional.ofNullable(electricArchiveRecordByCaseId.getUpdateTime()).orElse(electricArchiveRecordByCaseId.getCreateTime()));
            CaseStageDocumentInfoVo caseStageDocumentInfoVo = voList.get(voList.size() - 1);
            caseStageDocumentInfoVo.getCaseStageRelateDocumentList().add(tempData);
            tempData.setDocumentRelateAttachmentList(new ArrayList<>());
        }
    }

    /**
     * 增加涉嫌犯罪案件移送记录
     *
     * @param currentRecord
     * @param caseId
     * @param caseDetailDocInfoList
     */
    private void addLawenforceCaseTransferRecord(CaseStageLinkRelateDocumentVo currentRecord, String caseId, List<CaseStageLinkRelateDocumentVo> caseDetailDocInfoList) {

        //非正常状态的不处理
        if (!DocumentRecordStatusEnum.NORMAL.getCode().equals(currentRecord.getDocumentRecordStatus())) {
            return;
        }

        CaseBaseInfoQueryDto caseBaseInfoQueryDto = lawenforceBusinessService.readCaseBaseInfoByCaseId(caseId);
        if (!ObjectUtils.isEmpty(caseBaseInfoQueryDto)) {
            CaseStageLinkRelateDocumentVo documentVo = new CaseStageLinkRelateDocumentVo();
            documentVo.setDocumentId(caseBaseInfoQueryDto.getId());
            documentVo.setDocumentCatalogName("案件涉刑移送(" + caseBaseInfoQueryDto.getSwdwmc() + ")");
            documentVo.setCreateUserName(caseBaseInfoQueryDto.getCreateUserName());
            documentVo.setDocumentCreateTime(currentRecord.getApprovalFinishTime());
            documentVo.setDocumentRecordStatus(DocumentRecordStatusEnum.NORMAL.getCode());
            /*documentVo.setDocumentApprovalStatus(DocumentStatusEnum.CHECK_END.getCode());
            documentVo.setDocumentApprovalStatusName(DocumentStatusEnum.CHECK_END.getDes());*/
            documentVo.setLawenforceTransferRecordStatusName(caseBaseInfoQueryDto.getCaseStatusName());
            //documentVo.setLawenforceOpButton(caseBaseInfoQueryDto.getOpBotton());
            //只有详情按钮
            StringBuilder stringBuilder = new StringBuilder("detail");
            documentVo.setLawenforceOpButton(stringBuilder.toString());
            //设置是否修改申请记录
            documentVo.setIsLawenforceTransferRecord(YesOrNoEnum.YES.getCode());
            caseDetailDocInfoList.add(documentVo);
        }

    }

    /**
     * 添加文书修改申请记录
     *
     * @param currentRecord
     * @param caseId
     * @param caseDetailDocInfoList
     */
    private void addDocumentModifyRecord(CaseStageLinkRelateDocumentVo currentRecord, String caseId, List<CaseStageLinkRelateDocumentVo> caseDetailDocInfoList) {
        //撤回的不处理
        if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(currentRecord.getDocumentRecordStatus())) {
            return;
        }

        List<CaseDocumentModifyRecord> caseDocumentModifyRecordList = caseDocumentModifyRecordService.getCaseDocumentModifyRecordListByDocumentId(currentRecord.getDocumentId());
        if (ObjectUtils.isEmpty(caseDocumentModifyRecordList)) {
            //第一次修改按originalDocumentId查询
            caseDocumentModifyRecordList = caseDocumentModifyRecordService.getCaseDocumentModifyRecordListByOriginalDocumentId(caseId, currentRecord.getDocumentId());
        }

        if (!ObjectUtils.isEmpty(caseDocumentModifyRecordList)) {
            CaseDocumentModifyRecord caseDocumentModifyRecord = caseDocumentModifyRecordList.get(0);
            String modifyFlagId = caseDocumentModifyRecord.getModifyFlagId();
            List<CaseDocumentModifyRecord> recordList = null;
            if (ObjectUtils.isEmpty(modifyFlagId)) {
                CaseDocumentModifyRecordQueryDto queryDto = new CaseDocumentModifyRecordQueryDto();
                queryDto.setCaseId(caseId);
                queryDto.setDocumentCatalogCode(currentRecord.getDocumentCatalogCode());
                queryDto.setIsNeedApproval(YesOrNoEnum.YES.getCode());
                recordList = caseDocumentModifyRecordService.getCaseDocumentModifyRecordByCatalogCode(queryDto);
            } else {
                CaseDocumentModifyRecordQueryDto queryDto = new CaseDocumentModifyRecordQueryDto();
                queryDto.setCaseId(caseId);
                queryDto.setModifyFlagId(modifyFlagId);
                queryDto.setIsNeedApproval(YesOrNoEnum.YES.getCode());
                recordList = caseDocumentModifyRecordService.getCaseDocumentModifyRecordListByModifyFlagId(queryDto);
            }
            if (ObjectUtil.isNotEmpty(recordList)) {
                for (CaseDocumentModifyRecord modifyRecord : recordList) {
                    CaseStageLinkRelateDocumentVo documentVo = new CaseStageLinkRelateDocumentVo();
                    documentVo.setDocumentId(modifyRecord.getDocumentId());
                    documentVo.setDocumentKindCode(currentRecord.getDocumentKindCode());
                    documentVo.setDocumentKindName(currentRecord.getDocumentKindName());
                    //documentVo.setDocumentCatalogName(modifyRecord.getModifyTitle());
                    documentVo.setDocumentCatalogName(currentRecord.getDocumentCatalogName() + "修改申请");
                    documentVo.setDocumentCatalogCode(modifyRecord.getDocumentCatalogCode());
                    documentVo.setCreateUserName(modifyRecord.getCreateUserName());
                    Instant instant = modifyRecord.getCreateTime().toInstant();
                    ZoneId zoneId = ZoneId.systemDefault();
                    LocalDateTime createTime = instant.atZone(zoneId).toLocalDateTime();
                    documentVo.setDocumentCreateTime(createTime);
                    documentVo.setPartyId(currentRecord.getPartyId());
                    documentVo.setDocumentRecordStatus(DocumentRecordStatusEnum.NORMAL.getCode());
                    if (modifyRecord.getDocumentId().equals(currentRecord.getDocumentId())) {
                        documentVo.setDocumentApprovalStatus(currentRecord.getDocumentApprovalStatus());
                        documentVo.setDocumentApprovalStatusName(currentRecord.getDocumentApprovalStatusName());
                    } else {
                        //查询修改的文书记录
                        CaseDocumentRecord caseDocumentRecord = caseDocumentRecordMapper.selectByPrimaryKey(modifyRecord.getDocumentId());
                        documentVo.setDocumentApprovalStatus(caseDocumentRecord.getDocumentApprovalStatus());
                        documentVo.setDocumentApprovalStatusName(DocumentStatusEnum.getValueByCode(caseDocumentRecord.getDocumentApprovalStatus()));
                        if (DocumentStatusEnum.CHECKING.getCode().equals(caseDocumentRecord.getDocumentApprovalStatus())) {
                            //存在审批中的修改记录, 原纪录不显示其他按钮
                            currentRecord.setDocumentSentStatus(null);
                            currentRecord.setDocumentSentStatusName(null);
                            currentRecord.setDocumentSignstampedStatus(null);
                            currentRecord.setDocumentSignstampedStatusName(null);
                        }
                    }
                    if (!ObjectUtils.isEmpty(modifyRecord.getApprovalTime())) {
                        documentVo.setApprovalFinishTime(DateUtil.dateToLocalDateTime(modifyRecord.getApprovalTime()));
                    }
                    //设置是否修改申请记录
                    documentVo.setIsModifyApplyRecord(YesOrNoEnum.YES.getCode());
                    caseDetailDocInfoList.add(documentVo);
                }
            }

        }
    }


    /**
     * 添加案件移交记录
     *
     * @param voList 案件阶段列表
     * @param caseId 案件唯一标识
     * @return
     * @author lilihao
     * @date 2022/12/13 17:42
     */
    private void addCaseTransferRecord(List<CaseStageDocumentInfoVo> voList, String caseId) {
        voList.forEach(a -> {
            if (Constant.STRING_STAGE_CODE_CASE_INVESTIGATION.equals(a.getCaseStageCode())) {
                //加入移交记录
                Example example = new Example(CaseTransferRecord.class);
                example.createCriteria().andEqualTo("caseId", caseId).andNotEqualTo("transferType", Constant.STRING_3)
                        .andEqualTo("deleted", Constant.STRING_0);
                List<CaseTransferRecord> caseTransferRecordList = caseTransferRecordMapper.selectByExample(example);

                if (CollectionUtil.isNotEmpty(caseTransferRecordList)) {
                    caseTransferRecordList.forEach(b -> {
                        CaseStageLinkRelateDocumentVo relateDocumentVo = new CaseStageLinkRelateDocumentVo();
                        //标题
                        String transferTypeName = Constant.STRING_2.equals(b.getTransferType()) ? "案件移交" : "协查协办";
                        relateDocumentVo.setDocumentCatalogName(String.format(transferTypeName + "（%s）", b.getUnitName()));
                        //创建人
                        relateDocumentVo.setCreateUserName(b.getCreator());
                        //创建时间
                        relateDocumentVo.setDocumentCreateTime(cn.hutool.core.date.DateUtil.toLocalDateTime(b.getCreated()));
                        if (ObjectUtil.isNotNull(b.getApprovalFinishTime())) {
                            relateDocumentVo.setApprovalFinishTime(cn.hutool.core.date.DateUtil.toLocalDateTime(b.getApprovalFinishTime()));
                        }
                        //状态
                        relateDocumentVo.setDocumentApprovalStatus(b.getStatus());
                        //阶段编码
                        relateDocumentVo.setCaseStageCode(b.getStageCode());
                        //移交类型
                        relateDocumentVo.setTransferType(b.getTransferType());
                        relateDocumentVo.setSendUid(b.getSendUid());
                        //协查协办添加信息
                        if (Constant.STRING_1.equals(b.getTransferType())) {
                            relateDocumentVo.setSendUid(b.getSendUid());
                            relateDocumentVo.setDeptRelUid(b.getDeptRelUid());
                        }
                        a.getCaseStageRelateDocumentList().add(relateDocumentVo);

                        if (Constant.STRING_1.equals(b.getTransferType()) && StrUtil.isNotBlank(b.getFileUrl())) {
                            JSONArray jsonArray = JSONUtil.parseArray(b.getFileUrl());
                            List<FileInfoDto> fileList = JSONUtil.toList(jsonArray, FileInfoDto.class);
                            fileList.forEach(c -> {
                                CaseStageLinkRelateDocumentVo fileVo = new CaseStageLinkRelateDocumentVo();
                                fileVo.setDocumentCatalogName(String.format(transferTypeName + "（%s）", c.getFileName()));
                                fileVo.setCreateUserName(c.getFileDesc());
                                fileVo.setDocumentUrl(c.getFileUrl());
                                if (ObjectUtil.isNotNull(c.getCreateTime())) {
                                    fileVo.setDocumentCreateTime(cn.hutool.core.date.DateUtil.toLocalDateTime(c.getCreateTime()));
                                }
                                fileVo.setTransferType(Constant.STRING_444);
                                a.getCaseStageRelateDocumentList().add(fileVo);
                            });

                        }
                    });
                }
            }
        });
    }


    /**
     * 根据获取案件对应的送达及地址确认书编码
     *
     * @param caseId
     * @return {@link String}
     * @author liyafeng
     * @date 2022/8/4
     */
    @Override
    public String getCaseSendinfoConfirmCatalogCode(String caseId) {
        String caseSendinfoConfirmCatalogCode = "";
        CaseMainInfoVo caseMainInfoVo = getCaseMainInfo(caseId);
        String busiParamId = caseMainInfoVo.getBusiParamId();
        String documentKindCode = Constant.STRING_KIND_CODE_SDDZQRS;
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("busiParamId", busiParamId).andEqualTo("documentKindCode", documentKindCode).andEqualTo("isDeleted", "0").andNotLike("applyGroup", "%AY%").andNotLike("applyGroup", "%CZFL_TZ%");
        ;
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            caseSendinfoConfirmCatalogCode = configBusiParamDocumentInfos.get(0).getDocumentCatalogCode();
        }
        return caseSendinfoConfirmCatalogCode;
    }

    /**
     * 添加失效文书记录
     *
     * @param currentRecord
     * @param caseId
     * @param caseDetailDocInfoList
     */
    private void addInvalidDocumentRecord(CaseStageLinkRelateDocumentVo currentRecord, String caseId, List<CaseStageLinkRelateDocumentVo> caseDetailDocInfoList) {
        //需要添加失效记录的文书种类列表
        List<String> docKindList = Arrays.asList(DocumentKindEnum.DOC_KIND_SDDZQRS.getCode(),
                DocumentKindEnum.DOC_KIND_XWTZS.getCode(), DocumentKindEnum.DOC_KIND_SQWTS.getCode());
        if (!docKindList.contains(currentRecord.getDocumentKindCode())) {
            return;
        }

        //撤回的不处理
        if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(currentRecord.getDocumentRecordStatus())) {
            return;
        }

        Example hisDoc = new Example(CaseDocumentRecordHis.class);
        hisDoc.createCriteria().andEqualTo("caseId", caseId).andEqualTo("recordId", currentRecord.getDocumentId());
        hisDoc.orderBy("documentCreateTime").desc();
        List<CaseDocumentRecordHis> caseDocumentRecordHis = caseDocumentRecordHisMapper.selectByExample(hisDoc);
        if (!ObjectUtils.isEmpty(caseDocumentRecordHis)) {
            for (CaseDocumentRecordHis documentRecordHis : caseDocumentRecordHis) {
                CaseStageLinkRelateDocumentVo documentVo = new CaseStageLinkRelateDocumentVo();
                BeanUtils.copyProperties(documentRecordHis, documentVo);
                documentVo.setDocumentId(documentRecordHis.getId());
                documentVo.setMatchDocumentCatalogCode(currentRecord.getMatchDocumentCatalogCode());
                documentVo.setIsMatchDocument(currentRecord.getIsMatchDocument());
                documentVo.setAllRelationDocCatalogCodeList(currentRecord.getAllRelationDocCatalogCodeList());
                documentVo.setDocumentCatalogName(currentRecord.getDocumentCatalogName());
                documentVo.setCaseDocumentTypeFlag(currentRecord.getCaseDocumentTypeFlag());
                Instant instant = null;
                if (!ObjectUtils.isEmpty(documentRecordHis.getDocumentCreateTime())) {
                    instant = documentRecordHis.getDocumentCreateTime().toInstant();
                } else {
                    instant = documentRecordHis.getHisCreateTime().toInstant();
                }
                ZoneId zoneId = ZoneId.systemDefault();
                LocalDateTime createTime = instant.atZone(zoneId).toLocalDateTime();
                documentVo.setDocumentCreateTime(createTime);
                documentVo.setPartyId(currentRecord.getPartyId());
                //设置失效
                documentVo.setIsInvalid(Constant.STRING_1);
                caseDetailDocInfoList.add(documentVo);
            }
        }
    }

    /**
     * 【V1.4.1】描述：案件按环节操作所需信息获取
     *
     * @author tianrunjia
     * @date 2022-08-26
     */
    @Override
    public CaseDetailOperateDocInfoVo doGetCaseLinkOperateBusiInfo(CaseLinkOperateBusiInfoQueryDto queryDto) {
        //1、这里写的非常复杂，需后续优化
        CaseDetailOperateDocInfoVo caseDetailOperateDocInfoVo = getCaseDetailOperateDocInfoVo(queryDto.getCaseId(), queryDto.getCaseAssistId(), queryDto.getDocumentCatalogCode());
        return caseDetailOperateDocInfoVo;
    }

    /**
     * 【V1.4.1】描述：案件详情左边案件目录查询
     *
     * @param caseId 案件id
     * @author tianrunjia
     * @date 2022-08-27
     */
    @Override
    public List<CaseDocumentCatalogChainInfoVo> doGetCaseDocumentCatalogChainInfos(String caseId) {
        List<CaseDocumentCatalogChainInfoVo> caseSourceDocumentCatalogChainInfoVos = new ArrayList<>();
        List<CaseDocumentCatalogChainInfoVo> caseDocumentCatalogChainInfoVos = new ArrayList<>();
        //案件基础信息
        CaseMainInfoVo caseMainInfo = getCaseMainInfo(caseId);
        //案件案由、当事人类型
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();

        //1、组装预立案阶段
        //如果为案源案件 需展示案源相关文书
        if (ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
            CaseDocumentCatalogChainInfoVo caseDocumentCatalogChainInfoVo = new CaseDocumentCatalogChainInfoVo();
            caseDocumentCatalogChainInfoVo.setStageName(Constant.CASE_SOURCE_STAGE_YLA);
            caseDocumentCatalogChainInfoVo.setStageCode(Constant.CASE_SOURCE_STAGE_CODE);
            caseDocumentCatalogChainInfoVo.setStageStatus(Constant.STRING_1);
            Example partyExample = new Example(CaseSourcePartyInfo.class);
            partyExample.createCriteria().andEqualTo("caseSourceId", caseMainInfo.getId()).andEqualTo("status", Constant.STRING_1);
            List<CaseSourcePartyInfo> caseSourcePartyInfos = caseSourcePartyInfoMapper.selectByExample(partyExample);
            //文书列表
            List<CaseDocumentCatalogChainDetailVo> caseDocumentCatalogChainDetailVos = new ArrayList<>();
            CaseSourceLinkRelateDocumentQueryDto query = new CaseSourceLinkRelateDocumentQueryDto();
            query.setCaseSourceId(caseMainInfo.getId());
            query.setDocumentRecordStatus(Constant.STRING_1);
            List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList = caseSourceDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
            for (CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo : caseStageLinkRelateDocumentList) {
                caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                //多当事人
                if (caseSourcePartyInfos.size() > 1) {
                    String partyId = caseStageLinkRelateDocumentVo.getPartyId();
                    if (!ObjectUtils.isEmpty(partyId)) {
                        String[] partyIdArr = partyId.split(",");
                        if (partyIdArr.length == 1) {
                            CaseSourcePartyInfo caseSourcePartyInfo = caseSourcePartyInfoMapper.selectByPrimaryKey(partyId);
                            if (null != caseSourcePartyInfo) {
                                String documentKindName = caseStageLinkRelateDocumentVo.getDocumentKindName() + "(" + caseSourcePartyInfo.getPartyName() + ")";
                                caseStageLinkRelateDocumentVo.setDocumentKindName(documentKindName);
                            }
                        }
                    }
                }
                CaseDocumentCatalogChainDetailVo caseDocumentCatalogChainDetailVo = new CaseDocumentCatalogChainDetailVo();
                BeanUtils.copyProperties(caseStageLinkRelateDocumentVo, caseDocumentCatalogChainDetailVo);
                //关联附件
                CaseAttachmentInfoQueryDto attachmentInfoQueryDto = new CaseAttachmentInfoQueryDto();
                attachmentInfoQueryDto.setCaseId(caseId);
                attachmentInfoQueryDto.setDocumentCatalogCode(caseStageLinkRelateDocumentVo.getDocumentCatalogCode());
                attachmentInfoQueryDto.setPartyId(caseStageLinkRelateDocumentVo.getPartyId());
                List<CaseAttachmentInfoVo> caseAttachmentList = caseAppendixRecordService.getCaseAttachmentList(attachmentInfoQueryDto);
                List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
                caseAttachmentList.forEach(a -> {
                    DocumentRelateAttachmentVo vo = new DocumentRelateAttachmentVo();
                    BeanUtils.copyProperties(a, vo);
                    vo.setAttachmentId(a.getId());
                    vo.setAttachmentTitle(a.getAppendixName());
                    vo.setAttachmentUrl(a.getAppendixUrl());
                    vo.setAttachmentType(a.getAppendixType());
                    documentRelateAttachmentList.add(vo);
                });
                caseDocumentCatalogChainDetailVo.setDocumentRelateAttachmentList(documentRelateAttachmentList);

                caseDocumentCatalogChainDetailVos.add(caseDocumentCatalogChainDetailVo);
            }

            //案源附件查询
            List<CaseDocumentCatalogChainOfflineDetailVo> caseDocumentCatalogChainOfflineDetailVos = new ArrayList<>();
            Example materialExample = new Example(CaseSourceMaterialRecord.class);
            materialExample.createCriteria().andEqualTo("caseSourceId", caseId).andEqualTo("isDelete", Constant.STRING_0);
            List<CaseSourceMaterialRecord> caseSourceMaterialRecordList = caseSourceMaterialRecordMapper.selectByExample(materialExample);
            caseSourceMaterialRecordList.forEach(caseSourceMaterialRecord -> {
                CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo = new CaseStageLinkRelateDocumentVo();
                caseStageLinkRelateDocumentVo.setDocumentUrl(caseSourceMaterialRecord.getMaterialUrl());
                caseStageLinkRelateDocumentVo.setDocumentId(caseSourceMaterialRecord.getId());
                caseStageLinkRelateDocumentVo.setDocumentCreateTime(caseSourceMaterialRecord.getUploadTime());
                caseStageLinkRelateDocumentVo.setCreateUserName(caseSourceMaterialRecord.getUploadUserName());
                caseStageLinkRelateDocumentVo.setDocumentCatalogName(caseSourceMaterialRecord.getMaterialName());
                caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                if (!ObjectUtils.isEmpty(caseSourceMaterialRecord.getEvidenceUid())) {
                    //证据文件
                    caseStageLinkRelateDocumentVo.setIsEvidenceDoc(YesOrNoEnum.YES.getCode());
                }
                CaseDocumentCatalogChainOfflineDetailVo caseDocumentCatalogChainOfflineDetailVo = new CaseDocumentCatalogChainOfflineDetailVo();
                BeanUtils.copyProperties(caseStageLinkRelateDocumentVo, caseDocumentCatalogChainOfflineDetailVo);
                caseDocumentCatalogChainOfflineDetailVo.setDocumentTittle(caseSourceMaterialRecord.getMaterialName());
                caseDocumentCatalogChainOfflineDetailVos.add(caseDocumentCatalogChainOfflineDetailVo);
            });
            Collections.sort(caseStageLinkRelateDocumentList, (o1, o2) -> o1.getDocumentCreateTime().compareTo(o2.getDocumentCreateTime()));
            caseDocumentCatalogChainInfoVo.setCaseDocumentCatalogChainDetailVoList(caseDocumentCatalogChainDetailVos);

            caseDocumentCatalogChainInfoVo.setDocumentOfflineDetailVoList(caseDocumentCatalogChainOfflineDetailVos);
            //caseStageDocumentInfoVo.setCaseStageRelateDocumentList(caseStageLinkRelateDocumentList);
            //voList.add(caseStageDocumentInfoVo);
            caseSourceDocumentCatalogChainInfoVos.add(caseDocumentCatalogChainInfoVo);
        }

        //案件阶段查询
        ConfigDictionaryInfoQueryDto dto = new ConfigDictionaryInfoQueryDto();
        dto.setIsEffective(Constant.STRING_1);
        dto.setDicFieldCode(Constant.STRING_CASE_STAGE);
        //案件处理-流程取remark为名称
        if (Constant.STRING_2.equals(caseMainDetailInfoMapper.getHandleConclusionByCaseId(caseId))) {
            dto.setIsRemarkName(Constant.WHETHER_STRING_YES);
        }
        List<ConfigDictionaryInfoVo> configDictionaryInfoVos = configDictionaryInfoService.getConfigDictionaryList(dto);
        configDictionaryInfoVos.forEach(e -> {
            CaseDocumentCatalogChainInfoVo catalogChainInfoVo = new CaseDocumentCatalogChainInfoVo();
            catalogChainInfoVo.setStageCode(e.getDicCode());
            catalogChainInfoVo.setStageName(e.getDicName());
            caseDocumentCatalogChainInfoVos.add(catalogChainInfoVo);
        });


        List<CaseDocumentCatalogChainDetailVo> caseDocumentCatalogChainDetailVoList = caseDocumentRecordService.doGetAllCaseDocumentInfoEffectiveByCaseId(caseId);
        caseDocumentCatalogChainDetailVoList.forEach(h -> {
            String documentKindCode = h.getDocumentKindCode();
            //非草稿状态的文书设置相关状态的名称
            if (!DocumentRecordStatusEnum.DRAFT.getCode().equals(h.getDocumentRecordStatus())) {
                h.setDocumentApprovalStatusName(DocumentStatusEnum.getValueByCode(h.getDocumentApprovalStatus()));
                h.setDocumentSentStatusName(DocumentStatusEnum.getValueByCode(h.getDocumentSentStatus()));
                h.setDocumentSignstampedStatusName(DocumentStatusEnum.getValueByCode(h.getDocumentSignstampedStatus()));
            }
            h.setDocumentRecordStatusName(DocumentRecordStatusEnum.getValueByCode(h.getDocumentRecordStatus()));

            if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(documentKindCode)) {
                h.setCaseDocumentTypeFlag(Constant.STRING_1);
            }
            // 强制执行显示执行情况
            if (DocumentKindEnum.DOC_KIND_QZZXSQS.getCode().equals(documentKindCode)) {
                h.setCaseDocumentTypeFlag(Constant.STRING_2);
            }
            //增加处罚决定书是否展示公示详情处理
            if (Constant.STRING_KIND_CODE_CFJDS.equals(documentKindCode)) {
                //默认展示公示详情按钮
                h.setIsShowPublicity(YesOrNoEnum.YES.getCode());
                h.setIsShowPublicityName("展示公示");
            }
            //文书地址逻辑
            if (StringUtils.isNotBlank(h.getDocumentAftersealUrl())) {
                h.setDocumentUrl(h.getDocumentAftersealUrl());
            }
            if (StringUtils.isNotBlank(h.getDocumentAfterSignUrl())) {
                h.setDocumentUrl(h.getDocumentAfterSignUrl());
            }
            String documentCatalogCode = h.getDocumentCatalogCode();
            AuditDetailDocumentQueryDto queryAttachment = new AuditDetailDocumentQueryDto();
            queryAttachment.setCaseId(caseId);
            queryAttachment.setDocumentCatalogCode(documentCatalogCode);
            queryAttachment.setPartyId(h.getPartyId());
            List<DocAttachmentsVo> attachmentsList = caseAppendixRecordService.getDocLinkAttachments(queryAttachment);
            List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
            attachmentsList.forEach(a -> {
                DocumentRelateAttachmentVo vo = new DocumentRelateAttachmentVo();
                BeanUtils.copyProperties(a, vo);
                vo.setAttachmentId(a.getId());
                vo.setAttachmentTitle(a.getAppendixName());
                vo.setAttachmentUrl(a.getAppendixUrl());
                documentRelateAttachmentList.add(vo);
            });
            h.setDocumentRelateAttachmentList(documentRelateAttachmentList);


            //多当事人案件中，文书中配置关联对象为当事人的，文书列表中标题中增加当事人名称展示。示例：电子送达地址确认书（张三）。
            String partyId = h.getPartyId();
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                    && DocumentLinkObjectTypeEnum.PERSON.getCode().equals(h.getDocumentLinkObjectType())
                    && (!ObjectUtils.isEmpty(partyId) && !partyId.contains(","))) {
                //多当事人合并处罚不拼接当事人名称
                //查询当事人名称
                List<CasePartiesRecordVo> casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
                String partyName = "";
                for (CasePartiesRecordVo ele : casePartiesRecordList) {
                    String tmpPartyId = ele.getPartyId();
                    if (partyId.equals(tmpPartyId)) {
                        partyName = ele.getPartyName();
                        break;
                    }
                }
                h.setDocumentKindName(h.getDocumentKindName() + "(" + partyName + ")");
            }
        });

        //线下文书
        List<CaseDocumentCatalogChainOfflineDetailVo> documentOfflineDetailVoList = caseOfflineDocumentRecordService.doGetCaseDocumentCatalogChainOfflineDetailVo(caseId);
        String territoryCode = caseMainInfo.getCaseTerritoryCode();
        if (TerritoryCodeEnum.ZRZY.getCode().equals(territoryCode)) {
            //查询附件
            Example example = new Example(CaseAppendixRecord.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("appendixTypeId", AttachmentTypeEnum.ATTACHTYPE74.getCode()).andEqualTo("appendixStatus", Constant.STRING_1).andEqualTo("isDelete", Constant.STRING_0);
            List<CaseAppendixRecord> caseAppendixRecords = caseAppendixRecordMapper.selectByExample(example);
            if (!ObjectUtils.isEmpty(caseAppendixRecords)) {
                for (CaseAppendixRecord caseAppendixRecord : caseAppendixRecords) {
                    CaseDocumentCatalogChainOfflineDetailVo vo = new CaseDocumentCatalogChainOfflineDetailVo();
                    vo.setCaseStageCode(caseAppendixRecord.getCaseStageCode());
                    vo.setCaseStageName(caseAppendixRecord.getCaseStageName());
                    vo.setDocumentTittle(caseAppendixRecord.getAppendixName());
                    vo.setDocumentUrl(caseAppendixRecord.getAppendixUrl());
                    documentOfflineDetailVoList.add(vo);
                }
            }

        }
        caseDocumentCatalogChainInfoVos.forEach(h -> {
            List<CaseDocumentCatalogChainDetailVo> catalogChainDetailVos = new ArrayList<>();
            caseDocumentCatalogChainDetailVoList.forEach(g -> {
                if (h.getStageCode().equals(g.getCaseStageCode())) {
                    catalogChainDetailVos.add(g);
                }
            });
            List<CaseDocumentCatalogChainOfflineDetailVo> offlineDetailVos = new ArrayList<>();
            documentOfflineDetailVoList.forEach(i -> {
                if (h.getStageCode().equals(i.getCaseStageCode())) {
                    offlineDetailVos.add(i);
                }
            });
            h.setCaseDocumentCatalogChainDetailVoList(catalogChainDetailVos);
            h.setDocumentOfflineDetailVoList(offlineDetailVos);
        });

        int removestageIndex = 10; //默认一个值

        for (int i = 0; i < caseDocumentCatalogChainInfoVos.size(); i++) {
            if (ObjectUtil.isNotEmpty(caseMainInfo.getCaseCurrentStageCode()) && caseMainInfo.getCaseCurrentStageCode().equals(caseDocumentCatalogChainInfoVos.get(i).getStageCode())) {
                if (i == caseDocumentCatalogChainInfoVos.size() - 1) {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("1");
                } else {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("2");
                }
            } else {
                if (caseDocumentCatalogChainInfoVos.get(i).getCaseDocumentCatalogChainDetailVoList().size() <= 0) {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("3");
                } else {
                    //caseDocumentCatalogChainInfoVos.get(i).setStageStatus("2");
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("1");
                    /*if(i>0){
                        if(caseDocumentCatalogChainInfoVos.get(i-1).getCaseDocumentCatalogChainDetailVoList().size()==0
                                && caseDocumentCatalogChainInfoVos.get(i-1).getDocumentOfflineDetailVoList().size()==0){
                            removestageIndex = i-1;
                        }else {
                            caseDocumentCatalogChainInfoVos.get(i-1).setStageStatus("1");
                        }
                    }*/
                }
            }
        }

        /*if(removestageIndex<10){
            caseDocumentCatalogChainInfoVos.remove(removestageIndex);
        }*/


//        if("1".equals(caseDocumentCatalogChainInfoVos.get(caseDocumentCatalogChainInfoVos.size()-2))){
//            caseDocumentCatalogChainInfoVos.get(caseDocumentCatalogChainInfoVos.size()-2).setStageStatus("2");
//        }
        // 增加电子卷宗的数据
        addEletricArchiveLeft(caseId, caseDocumentCatalogChainInfoVos);
        caseSourceDocumentCatalogChainInfoVos.addAll(caseDocumentCatalogChainInfoVos);
        return caseSourceDocumentCatalogChainInfoVos;
    }


    /**
     * 电子卷宗
     *
     * @param caseId
     * @param caseDocumentCatalogChainInfoVos
     */
    private void addEletricArchiveLeft(String caseId, List<CaseDocumentCatalogChainInfoVo> caseDocumentCatalogChainInfoVos) {
        CaseElectricArchiveRecord electricArchiveRecordByCaseId = caseElectricArchiveRecordService.getElectricArchiveRecordByCaseId(caseId);
        if (null != electricArchiveRecordByCaseId) {
            CaseDocumentCatalogChainDetailVo caseDocumentCatalogChainDetailVo = new CaseDocumentCatalogChainDetailVo();
            caseDocumentCatalogChainDetailVo.setDocumentUrl(electricArchiveRecordByCaseId.getArchiveUrl());
            caseDocumentCatalogChainDetailVo.setDocumentKindName("电子卷宗");
            CaseDocumentCatalogChainInfoVo caseDocumentCatalogChainInfoVo = caseDocumentCatalogChainInfoVos.get(caseDocumentCatalogChainInfoVos.size() - 1);
            caseDocumentCatalogChainInfoVo.getCaseDocumentCatalogChainDetailVoList().add(caseDocumentCatalogChainDetailVo);
            caseDocumentCatalogChainDetailVo.setDocumentRelateAttachmentList(new ArrayList<>());
        }
    }


    /**
     * 【V1.4.1】描述：案件按环节操作所需信息获取
     *
     * @author tianrunjia
     * @date 2022-08-26
     */
    private CaseDetailOperateDocInfoVo getCaseDetailOperateDocInfoVo(String caseId, String caseAssistId, String documentCatalogCode) {
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        //获取当事人列表
        List<CasePartiesRecordVo> caseParties = casePartiesRecordService.getCasePartiesInfo(caseId);
        /*String currentLinkCode = caseMainInfo.getCaseCurrentLinkCode();
        if(StringUtils.isNotBlank(caseAssistId)){//如果是子流程的操作，则获取子流程相关信息
            CaseAssistMainInfo caseAssistMainInfo = caseAssistMainInfoService.doGetCaseAssistMainInfoById(caseAssistId);
            if(ObjectUtils.isEmpty(caseAssistMainInfo)){
                throw new BusinessException("案件子流程记录缺失！");
            }
            currentLinkCode = caseAssistMainInfo.getCaseAssistCurrentLinkCode();
        }*/
        /*ConfigWorkFlowDocument configWorkFlowDocument = configWorkFlowDocum/doAgreeAuditentService.getConfigWorkFlowDocumentByLinkAndCatalogCode(caseMainInfo.getCaseFlowCode(),caseMainInfo.getCaseFlowVersion()
                    ,currentLinkCode,documentCatalogCode);*/

        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDetailByDocumentCatalogCode(documentCatalogCode);
        if (ObjectUtils.isEmpty(configBusiParamDocumentInfo)) {
            throw new BusinessException("文书配信息（CONFIGBUSIPARAMDOCUMENTINFO）缺失！");
        }
        String busiParamId = caseMainInfo.getBusiParamId();

        CaseDetailOperateDocInfoVo operateDocInfo = new CaseDetailOperateDocInfoVo();
        operateDocInfo.setCaseId(caseId);
        operateDocInfo.setDocumentCatalogCode(documentCatalogCode);
        operateDocInfo.setDocumentKindCode(configBusiParamDocumentInfo.getDocumentKindCode());
        operateDocInfo.setDocumentKindName(configBusiParamDocumentInfo.getDocumentKindName());
        //根据文书目录编码查询关联文书 TODO 重复 后续优化
        List<String> allRelationDocCatalogCodeList = getALLRelationDocCatalogCodeList(busiParamId, documentCatalogCode);
        operateDocInfo.setAllRelationDocCatalogCodeList(allRelationDocCatalogCodeList);
        MachDocumentInfoVo machDocumentInfoVo = getMachDocumentInfo(busiParamId, documentCatalogCode);
        operateDocInfo.setMachDocumentInfoVo(machDocumentInfoVo);
        //查看是否已经有生成对应的文书
        CaseDocumentRecord caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, documentCatalogCode);
        //判断是否是撤回状态
        if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
            operateDocInfo.setDocumentId(caseDocumentRecord.getId());

            String documentStatus = caseDocumentRecord.getDocumentRecordStatus();
            if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(documentStatus)) {
                caseDocumentRecord = null;
            } else {
                //有效的且已生成的文书
                //组装 文书已经生成且待签字确认的关联当事人id列表
                //根据案件id+文书种类编码查询文书记录
                CaseDocumentRecordQueryDto queryDocument = new CaseDocumentRecordQueryDto();
                queryDocument.setCaseId(caseId);
                queryDocument.setDocumentKindCode(configBusiParamDocumentInfo.getDocumentKindCode());
                List<CaseDocumentRecordVo> documentRecordList = caseDocumentRecordService.getCaseDocumentRecordList(queryDocument);
                List<String> docIsExistsAndWaitToSignRelatedPartyIdList = new ArrayList<>();
                if (!ObjectUtils.isEmpty(documentRecordList) && documentRecordList.size() > 0) {
                    for (CaseDocumentRecordVo ele : documentRecordList) {
                        String signStatus = ele.getDocumentSignstampedStatus();
                        if (DocumentStatusEnum.WAIT_TO_CONFIRM.getCode().equals(signStatus)) {
                            String partyIdInfo = ele.getPartyId();
                            if (!ObjectUtils.isEmpty(partyIdInfo)) {
                                if (partyIdInfo.indexOf(Constant.STRING_COMMA) > 0) {
                                    String[] arr = partyIdInfo.split(Constant.STRING_COMMA);
                                    docIsExistsAndWaitToSignRelatedPartyIdList.addAll(Arrays.asList(arr));
                                    break;
                                } else {
                                    docIsExistsAndWaitToSignRelatedPartyIdList.add(partyIdInfo);
                                }
                            }
                        }
                    }
                }
                operateDocInfo.setDocIsExistsAndWaitToSignRelatedPartyIdList(docIsExistsAndWaitToSignRelatedPartyIdList);
            }
        }
        List<CasePartyRelateDocInfoVo> casePartiesKeyInfoVos = new ArrayList<>();
        CasePartyRelateDocInfoVo casePartyRelateDocInfo;
        for (CasePartiesRecordVo party : caseParties) {
            casePartyRelateDocInfo = new CasePartyRelateDocInfoVo();
            BeanUtils.copyProperties(party, casePartyRelateDocInfo);
            casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.NO.getCode());
            //查看该当事人是否已经添加该文书
            Example queryCountExample = new Example(CaseDocumentRecord.class);
            queryCountExample.createCriteria().andEqualTo("caseId", caseId)
                    .andEqualTo("documentCatalogCode", documentCatalogCode)
                    .andEqualTo("partyId", casePartyRelateDocInfo.getPartyId())
                    //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                    .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
            int count = caseDocumentRecordMapper.selectCountByExample(queryCountExample);
            if (count > 0) {
                casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.YES.getCode());
            }
            casePartyRelateDocInfo.setIsAddedThisDocName(YesOrNoEnum
                    .getValueByCode(casePartyRelateDocInfo.getIsAddedThisDoc()));
            casePartiesKeyInfoVos.add(casePartyRelateDocInfo);
        }
        operateDocInfo.setDocRelatePartiesList(casePartiesKeyInfoVos);
        //判断是否是案件操作文书
        boolean isCaseStatusChangeDoc = false;
        if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(configBusiParamDocumentInfo.getDocumentKindCode())) {
            isCaseStatusChangeDoc = true;
            operateDocInfo.setCaseDocumentTypeFlag(Constant.STRING_1);
        }
        String handleType = caseMainInfo.getHandleType();
        //文书是否处在不可处理的状态下（审批中）
        boolean docIsOutOfDealStatus = false;
        if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
            String docStatus = caseDocumentRecord.getDocumentAuditStatus();
            if ("pending".equals(docStatus)) {
                docIsOutOfDealStatus = true;
            }
        }

        operateDocInfo.setIsNeedApproval(configBusiParamDocumentInfo.getIsApprove());

        return operateDocInfo;
    }

    /**
     * 描述： 工作台--代办任务列表+全部任务(新)
     *
     * @return {@link List< TaskVo>}
     * @author: zhengqiang
     * @date: 2022/10/12
     * @param: caseDto
     **/
    //读库注解
    @DS("punishRead")
    @Override
    public List<TaskVo> getApproveTaskListNew(CaseQueryDto caseDto) {
        if (caseDto.getLength() > 1000) {
            throw new BusinessException("每页条数不能超过1000");
        }
        //处理当事人查询类别
        dealCaseQueryDto(caseDto);
        PageHelper.startPage(caseDto.getPageNum(), caseDto.getLength());
        //失效日期判断
        checkTimeColor(caseDto);
        //判断标签
        checkCaseTag(caseDto);
        //机构判断
        checkOrgCode(caseDto);
        //是否查询简案快办处理
        dealQueryFastCaseFlag(caseDto);
        List<TaskVo> list = null;
        if (Constant.STRING_2.equals(caseDto.getQueryListType())) {
            if (StringUtils.isNotEmpty(caseDto.getEnforceRegiCode())) {
                handleLimitArea(caseDto);
            }
            list = caseMainInfoMapper.getTodoTaskList(caseDto);
        } else {
            return getStageCaseListNew(caseDto);
        }
        if (list != null && list.size() > 0) {
            // 查询案由信息
            List<String> caseIds = list.stream().map(TaskVo::getCaseId).collect(Collectors.toList());
            List<CaseReasonMainRecordByCaseIdVo> recordsByCaseIds = caseReasonMainRecordMapper.getRecordsByCaseIds(caseIds);

            List<CasePartiesRecord> casePartiesRecordList = new ArrayList<>();
            List<CasePartiesLegalInfo> partiesLegalList = new ArrayList<>();
            List<CaseMainDetailSimpleInfo> caseMainDetailSimpleInfos = new ArrayList<>();
            // 如果是公安委托执法，查询案件当事人证件信息与交通信息
            if (StrUtil.equals(caseDto.getIsPublicSecurity(), "1")){
                getPartiesAndDetail(caseIds, casePartiesRecordList, partiesLegalList, caseMainDetailSimpleInfos);
            }

            for (TaskVo vo : list) {
                if(!Objects.equals(caseDto.getEntrust(), "0")){
                    // 设置委托执法标签
                    recordsByCaseIds.stream().filter(r -> Objects.equals(vo.getCaseId(), r.getCaseId()))
                            .findFirst().ifPresent(info -> assembleEntrustByTaskVO(vo, info));
                    if (StrUtil.equals(caseDto.getIsPublicSecurity(), "1")){
                        //设置交通信息
                        caseMainDetailSimpleInfos.stream().filter(data -> Objects.equals(data.getCaseId(), vo.getCaseId()))
                                .findFirst().ifPresent(info -> assembleTrafficInfoByTaskVO(info, vo));
                        //设置当事人的证据信息
                        casePartiesRecordList.stream().filter(data -> Objects.equals(data.getCaseId(), vo.getCaseId()))
                                .findFirst().ifPresent(info -> assemblePartiesInfoByTaskVO(info, partiesLegalList, vo));
                    }
                }
                String caseId = vo.getCaseId();
                //1.循环设置处理人员
                Example example = new Example(CaseHandlePersonRecord.class);
                example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
                example.orderBy("handlePersonType").asc();
                List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(example);
                for (CaseHandlePersonRecord caseHandlePersonRecord : handlePersonRecords) {
                    if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                        vo.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                    } else if (Constant.STRING_2.equals(caseHandlePersonRecord.getHandlePersonType())) {
                        vo.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                    }
                }
                String handPersonName = handlePersonRecords.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
                vo.setHandlePersonName(handPersonName);
                //鉴定 中止与恢复 办案期限计算
                CaseMainInfoStatusChangeRecord record = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(caseId, CaseStatusChangeTypeEnum.SUSPEND.getCode());
                if (null != record) {
                    //暂停，则原有的办案期限+（当前日期-中止日期）
                    if (Constant.STRING_1.equals(record.getStatus())) {
                        long days = DateUtil.calculatePastDays(record.getChangeEffectTime().toLocalDate());
                        vo.setCaseTimeLimit(DateUtils.addDays(vo.getCaseTimeLimit(), (int) days));
                    }
                    //恢复，则原有的办案期限+（恢复日期-中止日期）
                }
                //2.计算剩余时间
                vo.setTimeColor("");
                if (vo.getCaseTimeLimit() != null && vo.getCaseVerdictEndTime() == null
                        && !CaseStatusEnum.END_CASE.getCode().equals(vo.getCaseStatus())
                        && !CaseStatusEnum.END_CRIMINAL_TRANSFER.getCode().equals(vo.getCaseStatus())
                        && !CaseStatusEnum.TRANSFERRING.getCode().equals(vo.getCaseStatus())) {
                    int timeLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), vo.getCaseTimeLimit());
                    handleRemainTimes(timeLimit, vo);
                    //3.红橙黄绿蓝
                    //分红（当前日期-办案期限<0)、黄(当前日期-办案期限<=7)、蓝色(当前日期-办案期限>7) 2022-10-12
                    if (timeLimit < Constant.INTEGER_0) {
                        vo.setTimeColor("red");
                    } else if (timeLimit <= Constant.INTEGER_7) {
                        vo.setTimeColor("yellow");
                    } else if (timeLimit > Constant.INTEGER_7) {
                        vo.setTimeColor("blue");
                    }
                    //暂停设置为灰色
                    if (CaseStatusEnum.SUSPEND.getCode().equals(vo.getCaseStatus())) {
                        vo.setTimeColor("gray");
                    }
                }

                //4.caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
                vo.setCaseType(CaseTypeEnum.getValueByCode(vo.getCaseType()));
                //5.如果是公司主体，返回公司信息
                if (StringUtils.isNotEmpty(vo.getPartyType()) && vo.getPartyType().equals(Constant.STRING_2)) {
                    CasePartiesLegalInfo legalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(vo.getPartyId());
                    vo.setLegalInfo(legalInfo);
                }
                //6. 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
                vo.setCaseStatus(CaseStatusEnum.getValueByCode(vo.getCaseStatus()));
                /*// 多当事人企业详情
                if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(vo.getCasePartiesReasonType())) {
                    Example exampleParty = new Example(CasePartiesRecord.class);
                    exampleParty.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
                    int pn = casePartiesRecordMapper.selectCountByExample(exampleParty);
                    if (pn > 1) {
                        vo.setPartyType("multitude");
                        List<CasePartiesRecordVo> casePartiesRecords = casePartiesRecordService.getCasePartiesInfo(caseId);
                        //vo.setPartyName(casePartiesRecords.get(0).getPartyName() + "等" + pn + "个");
                        vo.setLegalInfo(null);
                        String partyNames = casePartiesRecords.stream().map(CasePartiesRecordVo::getPartyName).collect(Collectors.joining(","));
                        vo.setPartyName(partyNames);
                    }
                }*/

                List<CasePartiesRecordVo> casePartiesRecords = casePartiesRecordService.getCasePartiesInfoVoList(caseId);
                if (ObjectUtil.isNotEmpty(casePartiesRecords)) {
                    vo.setPartyType("multitude");
                    vo.setLegalInfo(null);
                    String partyNames = casePartiesRecords.stream().map(CasePartiesRecordVo::getPartyName).collect(Collectors.joining(","));
                    vo.setPartyName(partyNames);
                }

                //人社和应急案由
                if (StrUtil.isNotEmpty(vo.getPersonReasonName())) {
                    vo.setOtherReasonNames(vo.getPersonReasonName());
                }
                if (StrUtil.isNotEmpty(vo.getCaseEmergencyReasonContent())) {
                    List<CaseEmergencyReasonInfoDto> emergencyReasonList = JSON.parseArray(vo.getCaseEmergencyReasonContent(), CaseEmergencyReasonInfoDto.class);
                    List<String> reasonNameList = CollUtil.newArrayList();
                    emergencyReasonList.forEach(u -> reasonNameList.add(u.getEmergencyReasonName()));
                    vo.setOtherReasonNames(CollUtil.join(reasonNameList, ","));
                }
            }
        }
        return list;
    }

    /**
     * 组装是否委托执法信息
     * @param vo
     * @param caseReasonMainRecord
     */
    private void assembleEntrustByTaskVO(TaskVo vo, CaseReasonMainRecordByCaseIdVo caseReasonMainRecord) {
        vo.setHadEntrustCase(true);
        vo.setSxTypeStr("委托执法");
        vo.setClientOrgName(StrUtil.isBlank(caseReasonMainRecord.getClientDeptName()) ? caseReasonMainRecord.getClientOrgName() : caseReasonMainRecord.getClientDeptName());
        vo.setPublicSecurityItemCode(caseReasonMainRecord.getPublicSecurityItemCode());
    }

    /**
     * 设置交通信息
     * @param info
     * @param vo
     */
    private void assembleTrafficInfoByTaskVO(CaseMainDetailSimpleInfo info, TaskVo vo){
        vo.setLicenseFileNumber(info.getLicenseFileNumber());
        vo.setTrafficWay(info.getTrafficWay());
        vo.setLicensePlateNumber(info.getLicensePlateNumber());
    }

    /**
     * 设置当事人的证件信息
     * @param record
     * @param partiesLegalList
     * @param vo
     */
    private void assemblePartiesInfoByTaskVO(CasePartiesRecord record, List<CasePartiesLegalInfo> partiesLegalList, TaskVo vo){
        if (Objects.equals(record.getPartyType(), "1")){
            // 个人
            vo.setIdentityType(CertTypeEnum.getValueByCode(record.getPartyIdentityType()));
            vo.setIdentityNumber(record.getPartyIdentityCode());
        }else {
            // 如果是法人，那么就要从法人列表中筛选
            partiesLegalList.stream().filter(data -> Objects.equals(data.getId(), record.getPartyId()))
                    .findFirst().ifPresent(legalInfo -> assembleLegalInfoByTaskVO(vo, legalInfo));
        }
    }

    /**
     * 组装法人信息
     * @param vo
     * @param legalInfo
     */
    private void assembleLegalInfoByTaskVO(TaskVo vo, CasePartiesLegalInfo legalInfo){
        vo.setUniscId(legalInfo.getUniscid());
        vo.setIdentityType(CertTypeEnum.getValueByCode(legalInfo.getLegalCertType()));
        vo.setIdentityNumber(legalInfo.getLegalCertNo());
    }


    /**
     * 是否查询简案快办标志处理
     *
     * @param caseDto
     */
    private void dealQueryFastCaseFlag(CaseQueryDto caseDto) {
        //是否查询简案快办标志处理, 立案管理排除简案快办案件
        if (CaseStageEnum.CASE_REGISTER.getDes().equals(caseDto.getCaseStage())
                && !CaseTypeEnum.FAST_PROCEDURE.getCode().equals(caseDto.getCaseType())) {
            caseDto.setIsQueryFastCase(YesOrNoEnum.NO.getCode());
        }
    }


    /**
     * 描述： 各阶段案件查询列表(新)
     *
     * @return {@link List< TaskVo>}
     * @author: zhengqiang
     * @date: 2023/5/26
     * @param: caseDto
     **/
    public List<TaskVo> getStageCaseListNew(CaseQueryDto caseDto) {
        List<TaskVo> list = caseMainInfoMapper.getStageCaseListNew(caseDto);
        if (list != null && list.size() > 0) {
            List<String> caseIds = list.stream().map(TaskVo::getCaseId).collect(Collectors.toList());
            List<CaseReasonMainRecordByCaseIdVo> recordsByCaseIds = caseReasonMainRecordMapper.getRecordsByCaseIds(caseIds);
            for (TaskVo vo : list) {
                if(!Objects.equals(caseDto.getEntrust(), "0")){
                    CaseReasonMainRecordByCaseIdVo caseReasonMainRecord = recordsByCaseIds.stream().filter(r -> Objects.equals(vo.getCaseId(), r.getCaseId())).findFirst().orElse(null);
                    if (!Objects.isNull(caseReasonMainRecord)){
                        vo.setHadEntrustCase(true);
                        vo.setSxTypeStr("委托执法");
                        vo.setClientOrgName(caseReasonMainRecord.getClientOrgName());
                    }else {
                        vo.setHadEntrustCase(false);
                    }
                }
                String caseId = vo.getCaseId();
                //1.循环设置处理人员
                Example example = new Example(CaseHandlePersonRecord.class);
                example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
                example.orderBy("handlePersonType").asc();
                List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(example);
                for (CaseHandlePersonRecord caseHandlePersonRecord : handlePersonRecords) {
                    if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                        vo.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                    } else if (Constant.STRING_2.equals(caseHandlePersonRecord.getHandlePersonType())) {
                        vo.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                    }
                }
                String handPersonName = handlePersonRecords.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
                vo.setHandlePersonName(handPersonName);
                //鉴定 中止与恢复 办案期限计算
                CaseMainInfoStatusChangeRecord record = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(caseId, CaseStatusChangeTypeEnum.SUSPEND.getCode());
                if (null != record) {
                    //暂停，则原有的办案期限+（当前日期-中止日期）
                    if (Constant.STRING_1.equals(record.getStatus())) {
                        long days = DateUtil.calculatePastDays(record.getChangeEffectTime().toLocalDate());
                        vo.setCaseTimeLimit(DateUtils.addDays(vo.getCaseTimeLimit(), (int) days));
                    }
                    //恢复，则原有的办案期限+（恢复日期-中止日期）
                }
                //2.计算剩余时间
                vo.setTimeColor("");
                if (vo.getCaseTimeLimit() != null && vo.getCaseVerdictEndTime() == null
                        && !CaseStatusEnum.END_CASE.getCode().equals(vo.getCaseStatus())) {
                    int timeLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), vo.getCaseTimeLimit());
                    handleRemainTimes(timeLimit, vo);
                    //3.红橙黄绿蓝
                    //分红（当前日期-办案期限<0)、黄(当前日期-办案期限<=7)、蓝色(当前日期-办案期限>7) 2022-10-12
                    if (timeLimit < Constant.INTEGER_0) {
                        vo.setTimeColor("red");
                    } else if (timeLimit <= Constant.INTEGER_7) {
                        vo.setTimeColor("yellow");
                    } else if (timeLimit > Constant.INTEGER_7) {
                        vo.setTimeColor("blue");
                    }
                    //暂停设置为灰色
                    if (CaseStatusEnum.SUSPEND.getCode().equals(vo.getCaseStatus())) {
                        vo.setTimeColor("gray");
                    }
                }

                //4.caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
                vo.setCaseType(CaseTypeEnum.getValueByCode(vo.getCaseType()));
                //5.如果是公司主体，返回公司信息
                if (StringUtils.isNotEmpty(vo.getPartyType()) && vo.getPartyType().equals(Constant.STRING_2)) {
                    CasePartiesLegalInfo legalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(vo.getPartyId());
                    vo.setLegalInfo(legalInfo);
                }
                if (StringUtils.isNotEmpty(vo.getPartyName()) && vo.getPartyName().contains(",")) {
                    vo.setPartyType("multitude");
                }

                //6. 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
                vo.setCaseStatus(CaseStatusEnum.getValueByCode(vo.getCaseStatus()));

            }
        }
        return list;
    }

    /**
     * 描述： 颜色统计(新)
     *
     * @return {@link ColorSumVo}
     * @author: zhengqiang
     * @date: 2022/10/12
     * @param: caseDto
     **/
    //读库注解
    @DS("punishRead")
    @Override
    public ColorSumVo getColorStatisticsNew(CaseQueryDto caseDto) {
        //处理当事人查询类别
        dealCaseQueryDto(caseDto);
        //分红（当前日期-办案期限<0)、黄(当前日期-办案期限<=7)、蓝色(当前日期-办案期限>7)
        //判断标签
        checkCaseTag(caseDto);
        //机构判断
        checkOrgCode(caseDto);
        /*int total = 0;
        if (Constant.STRING_2.equals(caseDto.getQueryListType())) {
            total = caseMainInfoMapper.getTodoTaskList(caseDto).size();
        } else {
            total = caseMainInfoMapper.getApproveTaskListNew(caseDto).size();
        }*/
        //caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 3));
        /*caseDto.setTimeLimitEnd(BaseUtil.getNowTimeStamp());
        caseDto.setTimeLimitStart(Timestamp.valueOf("1999-01-01 00:00:00"));*/
        int red = 0;
        caseDto.setCaseTimeColor("red");
        if (Constant.STRING_2.equals(caseDto.getQueryListType())) {
            red = caseMainInfoMapper.getTodoTaskColorStatistics(caseDto);
        } else {
            red = caseMainInfoMapper.getColorStatisticsNew(caseDto);
        }
       /* caseDto.setTimeLimitStart(BaseUtil.getNowTimeStamp());
        caseDto.setTimeLimitEnd(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayEndDate(), 7));*/
        int yellow = 0;
        caseDto.setCaseTimeColor("yellow");
        if (Constant.STRING_2.equals(caseDto.getQueryListType())) {
            yellow = caseMainInfoMapper.getTodoTaskColorStatistics(caseDto);
        } else {
            yellow = caseMainInfoMapper.getColorStatisticsNew(caseDto);
        }
       /* caseDto.setTimeLimitStart(BaseUtil.getTimeStampAfterDateByDays(BaseUtil.getTodayStartDate(), 7));
        caseDto.setTimeLimitEnd(null);*/
        /*int blue = 0;
        if (Constant.STRING_2.equals(caseDto.getQueryListType())) {
            blue = caseMainInfoMapper.getTodoTaskColorStatistics(caseDto);
        } else {
            blue = caseMainInfoMapper.getColorStatisticsNew(caseDto);
        }*/
        ColorSumVo sumVo = new ColorSumVo();
        //sumVo.setBlueNum(blue);
        sumVo.setRedNum(red);
        sumVo.setYellowNum(yellow);
        //sumVo.setTotal(total);
        return sumVo;
    }

    /**
     * 描述： 异步推送结案的案件信息至外部系统
     *
     * @return
     * @author: zhengqiang
     * @date: 2022/10/20
     * @param: caseId
     **/
    @Override
    public void pushCaseToOutSys(String caseId) {
        ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
        singleThreadExecutor.execute(() -> {
            log.info("开始异步推送案件信息-caseId:【" + caseId + "】");
            CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
            //1.推送案件到事项抄告
            AddTrabeReBaseDto addTrabeReBaseDto = new AddTrabeReBaseDto();
            addTrabeReBaseDto.setCaseUid(caseId);
            addTrabeReBaseDto.setCreateOrgCode(caseMainInfo.getCaseOrgCode());
            addTrabeReBaseDto.setCreateOrgName(caseMainInfo.getCaseOrgName());
            //事项处理
            List<CaseReasonMainRecordVo> caseReasonMainRecords = caseReasonMainRecordService.getCaseReasonRecordListByCaseId(caseId);
            if (ObjectUtil.isNotEmpty(caseReasonMainRecords) && caseReasonMainRecords.size() > 0) {
                List<String> reasonList = caseReasonMainRecords.stream().map(e -> e.getCaseReasonCode()).collect(Collectors.toList());
                addTrabeReBaseDto.setPunishmentListCodeList(reasonList);
            }
            //办案人员处理
            List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
            if (!ObjectUtils.isEmpty(caseHandlePersonRecordList)) {
                CaseHandlePersonRecordVo caseHandlePersonRecordVo = caseHandlePersonRecordList.get(0);
                addTrabeReBaseDto.setContactUserName(caseHandlePersonRecordVo.getHandlePersonName());
                addTrabeReBaseDto.setContactUserPhone(ObjectUtils.isEmpty(caseHandlePersonRecordVo.getHandlePersonTel()) ? caseHandlePersonRecordVo.getHandleDeptTel() : caseHandlePersonRecordVo.getHandlePersonTel());
            }
            //当事人处理
            List<CasePartiesRecordVo> casePartiesInfoList = casePartiesInfoService.getCasePartiesInfo(caseId);
            String partyNames = casePartiesInfoList.stream().map(e -> e.getPartyName()).collect(Collectors.joining("、"));
            addTrabeReBaseDto.setPartyNames(partyNames);
            taskCenterService.saveCaseAutoAddTrabeReBase(addTrabeReBaseDto);
            log.info("推送案件到事项抄告结束");

            //2.推送案件到信息协助
            CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);

            if (!HandleTypeEnum.PART_PUNISH.getCode().equals(caseMainInfo.getHandleType())
                    && !Constant.STRING_1.equals(caseMainDetailInfo.getInvestConclusion())) {
                //不予处罚不需要推送
                return;
            }
            List<PunishCooInfoDto> infoCoordinaPunishRespList = new ArrayList<>();
            casePartiesInfoList.forEach(e -> {
                String punishKinds = caseMainDetailInfo.getPunishKinds();
                //分别处罚时: 处罚种类
                if (HandleTypeEnum.PART_PUNISH.getCode().equals(caseMainInfo.getHandleType())) {
                    Example auxiliaryExample = new Example(CaseMainDetailAuxiliaryInfo.class);
                    auxiliaryExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", e.getPartyId());
                    List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(auxiliaryExample);
                    if (!ObjectUtils.isEmpty(caseMainDetailAuxiliaryInfos)) {
                        CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfos.get(0);
                        if (!Constant.STRING_1.equals(caseMainDetailAuxiliaryInfo.getInvestConclusion())) {
                            //不予处罚不需要推送
                            return;
                        }
                        punishKinds = caseMainDetailAuxiliaryInfo.getPunishKinds();
                    }
                }

                List<String> punishKindList = Arrays.asList(punishKinds.split(","));
                //处罚主题类型 7-机构类主体 8-自然人主体
                String themeType = PartyTypeEnum.PERSON.getCode().equals(e.getPartyType()) ? "8" : "7";
                PunishCooInfoDto punishCooInfoDto = new PunishCooInfoDto();
                punishCooInfoDto.setThemeType(themeType);
                punishCooInfoDto.setUnicode(e.getPartyIdentityCode());
                punishCooInfoDto.setPunishTypeList(punishKindList);
                punishCooInfoDto.setPunishNameList(punishKindList);
                infoCoordinaPunishRespList.add(punishCooInfoDto);
            });
            PunishCooInfoRequest punishCooInfoRequest = new PunishCooInfoRequest(caseMainInfo.getCaseOrgCode(), infoCoordinaPunishRespList);
            taskCenterService.savePunishCooInfoPush(punishCooInfoRequest);
            log.info("推送案件到信息协同结束");
        });

    }

    /**
     * 描述：统一案件分页查询列表
     *
     * @author yehuafei
     * @date 2022-12-05
     */
    @Override
    public List<CaseInfoPageResponse> getCaseInfoList(CaseInfoPageRequest request) {
        if (request.getLength() > 200) {
            throw new BusinessException("每页最多不超过200条数据");
        }
        //失效日期判断
        request.checkTimeColor();
        //机构判断
        request.checkOrgCode();
        PageHelper.startPage(request.getPageNum(), request.getLength());
        List<CaseInfoPageResponse> list = caseMainInfoMapper.selectCaseInfoList(request);
        if (CollectionUtils.isNotEmpty(list) && list.size() > 0) {
            UserDTO userInfo = UserUtil.getUserInfo();
            if (ObjectUtil.isEmpty(userInfo) || StringUtils.isBlank(userInfo.getUserId().toString())) {
                throw new RuntimeException("登录用户信息获取失败");
            }
            String zfzh = caseHandlePersonRecordMapper.getZFZHByUserId(UserUtil.getUserInfo().getUserId().toString());
            for (CaseInfoPageResponse caseInfoPageResponse : list) {
                //首先判断数据来源是否浙江省统一办案系统
                if (Constant.STRING_1.equals(caseInfoPageResponse.getIsCFSystem())) {
                    //查询案件在处罚系统是否有数据
                    String punishCaseCode = caseInfoPageResponse.getCaseId();
                    String caseId = caseMainInfoMapper.getCFCaseIdByPunishCaseCode(punishCaseCode);
                    if (StringUtils.isNotBlank(caseId)) {
                        caseInfoPageResponse.setCaseId(caseId);
                        caseInfoPageResponse.setIsCFSystem(Constant.STRING_1);
                        //获取协办uid
                        //查询案源信息
                        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
                        CaseSourceRegisterMainInfo mainInfo = caseSourceRegisterMainInfoMapper.selectByPrimaryKey(caseId);
                        if (!ObjectUtils.isEmpty(mainInfo)) {
                            //检查转案源
                            caseInfoPageResponse.setCaseUid(mainInfo.getCaseSourceAppServiceId());
                        } else {
                            //检查直接立案
                            if (!ObjectUtils.isEmpty(caseMainInfo.getDataSourceServiceId()) && !caseMainInfo.getDataSourceServiceId().equals(caseId)) {
                                caseInfoPageResponse.setCaseUid(caseMainInfo.getDataSourceServiceId());
                            }
                        }
                    } else {
                        caseInfoPageResponse.setIsCFSystem(Constant.STRING_0);
                    }
                }
                //登录用户是否为案件办理人
                if (StringUtils.isNotBlank(zfzh)) {
                    caseInfoPageResponse.setLoginUserIfZfPeople(StringUtils.contains(caseInfoPageResponse.getZfPeopleCode(), zfzh));
                } else {
                    caseInfoPageResponse.setLoginUserIfZfPeople(false);
                }
                //设置案件时效
                this.setTimeColor(caseInfoPageResponse);
            }
        }
        return list;
    }

    private void setTimeColor(CaseInfoPageResponse caseInfoPageResponse) {
        //未作出处罚决定  计算时效
        if (ObjectUtils.isEmpty(caseInfoPageResponse.getPunishDate())) {
            //计算立案日期到现在的天数
            int registToNowDays = DateUtil.getBetweenDays(DateUtil.dateToString(caseInfoPageResponse.getCaseRegistTime(), DateUtil.date_sdf), DateUtil.dateToString(new Date(), DateUtil.date_sdf));
            int remainTime;
            if (caseInfoPageResponse.getLineCode().equals("A017")) {
                //人设条线 60天期限
                remainTime = 60 - registToNowDays;
            } else if (caseInfoPageResponse.getLineCode().equals("A024")) {
                //应急条线 30天期限
                remainTime = 30 - registToNowDays;
            } else {
                //常规条线 90天期限
                remainTime = 90 - registToNowDays;
            }
            int remainTimeAbs = Math.abs(remainTime);
            if (remainTime < 0) {
                caseInfoPageResponse.setTimeColor("red");
                caseInfoPageResponse.setRemainTime("超" + remainTimeAbs + "天");
            } else if (remainTime <= 3) {
                caseInfoPageResponse.setTimeColor("yellow");
                caseInfoPageResponse.setRemainTime("剩" + remainTimeAbs + "天");
            } else {
                caseInfoPageResponse.setTimeColor("blue");
                caseInfoPageResponse.setRemainTime("剩" + remainTimeAbs + "天");
            }
        }
    }

    /**
     * 描述：统一案件详情
     *
     * @author yehuafei
     * @date 2022-12-05
     */
    @Override
    public CaseInfoDetailResponse getCaseInfoDetail(String id) {
        CaseInfoDetailResponse caseInfoDetailResponse = caseMainInfoMapper.getCaseInfoDetailById(id);
        if (ObjectUtil.isEmpty(caseInfoDetailResponse)) {
            return new CaseInfoDetailResponse();
        }
        if (StringUtils.isNotBlank(caseInfoDetailResponse.getPunishDocumentNum())) {
            //获取行政处罚决定书pdf地址
            String xzcfJDSUrl = caseMainInfoMapper.getXzcfJDSUrl(caseInfoDetailResponse.getPunishDocumentNum());
            caseInfoDetailResponse.setXzcfJDSUrl(xzcfJDSUrl);
        }
        // 查询立案信息
        CaseInfoDetailLAXX laxx = caseMainInfoMapper.getCaseInfoDetailLAXX(id);
        caseInfoDetailResponse.setLaxx(laxx);
        //调查取证
        //        ...
        //处罚告知信息
        CaseInfoDetailCFGZ cfgz = caseMainInfoMapper.getCaseInfoDetailCFGZ(id);
        caseInfoDetailResponse.setCfgz(cfgz);
        //处罚决定信息
        CaseInfoDetailCFJD cfjd = caseMainInfoMapper.getCaseInfoDetailCFJD(id);
        caseInfoDetailResponse.setCfjd(cfjd);
        //处罚执行信息
        CaseInfoDetailCFZX cfzx = caseMainInfoMapper.getCaseInfoDetailCFZX(id);
        caseInfoDetailResponse.setCfzx(cfzx);
        //结案信息
        CaseInfoDetailJAXX jaxx = caseMainInfoMapper.getCaseInfoDetailJAXX(id);
        caseInfoDetailResponse.setJaxx(jaxx);
        //公示信息
        CaseInfoDetailGSXX gsxx = caseMainInfoMapper.getCaseInfoDetailGSXX(id);
        caseInfoDetailResponse.setGsxx(gsxx);
        return caseInfoDetailResponse;
    }

    @Override
    public List<CaseInformHisXZCFRecord> getCaseInformHisXZCFRecord(CaseInformHisXZCFRecordRequest request) {
        PageHelper.startPage(request.getPageNum(), request.getLength());
        //查询历史行政处罚记录
        List<CaseInformHisXZCFRecord> caseInformHisXZCFRecords = caseMainInfoMapper.getCaseInformHisXZCFRecord(request.getPartyId());
        caseInformHisXZCFRecords.forEach(item -> {
            item.setPunishKinds(PunishKindsEnum.getValueByCode(item.getPunishKinds()));
            //首先判断数据来源是否浙江省统一办案系统
            if (Constant.STRING_1.equals(item.getIsCFSystem())) {
                //查询案件在处罚系统是否有数据
                String punishCaseCode = item.getCaseId();
                String caseId = caseMainInfoMapper.getCFCaseIdByPunishCaseCode(punishCaseCode);
                if (StringUtils.isNotBlank(caseId)) {
                    item.setCaseId(caseId);
                    item.setIsCFSystem(Constant.STRING_1);
                } else {
                    item.setIsCFSystem(Constant.STRING_0);
                }
            }
        });
        return caseInformHisXZCFRecords;
    }

    /**
     * 【V1.0.0】描述：根据案件id获取加处罚款决定书填充信息
     *
     * @param caseId 案件id
     * @author yehuafei
     * @date 2022-12-13 09:33
     */
    @Override
    public JCFKJDSDocData getJCFKJDSDocData(String caseId, String partyId) {
        CaseMainInfoVo caseMainInfo = caseMainInfoMapper.selectCaseMainInfo(caseId);
        String handleType = caseMainInfo.getHandleType();
        // 查询 处罚决定书送达日期 处罚决定书文号 罚款金额 加处罚款金额
        JCFKJDSDocData data = caseMainInfoMapper.getJCFKJDSDocData(caseId, partyId, handleType);
        //获取处罚事项
        data.setCaseReasonName(caseReasonMainRecordService.getCaseReasonRecordByCaseId(caseId).getCaseReasonName());
        // 获取 行政决定履行催告书送达日期 催告书文号
        JCFKJDSDocData xzjdlxcgsData = caseDocumentRecordMapper.getXzjdlxcgsData(caseId, partyId, handleType);
        if (ObjectUtil.isNotEmpty(xzjdlxcgsData)) {
            data.setCgsSentDate(xzjdlxcgsData.getCgsSentDate());
            data.setCgsNumber(xzjdlxcgsData.getCgsNumber());
        }
        data.setPunishMoney(ConvertUpMoneyUtil.toChinese(data.getPunishMoney()));
        data.setAddPunishMoney(ConvertUpMoneyUtil.toChinese(data.getAddPunishMoney()));
        return data;
    }

    /**
     * 描述：处理案件查询条件
     *
     * @param caseDto 案例dto
     * @author shishengyao
     * @date 2022/10/19
     */
    private void dealCaseQueryDto(CaseQueryDto caseDto) {
        //处理当事人查询类别
        List<String> partySubclassTypeList = caseDto.getPartyNameTypeList();
        if (ObjectUtil.isNotEmpty(partySubclassTypeList)) {
            List<String> legalPartyTypeList = new ArrayList();
            for (String partySubclassType : partySubclassTypeList) {
                if (partySubclassType.startsWith(PartyTypeEnum.PERSON.getCode() + "_")) {
                    caseDto.setPersonPartyType(partySubclassType.replace(PartyTypeEnum.PERSON.getCode() + "_", ""));
                } else if (partySubclassType.startsWith(PartyTypeEnum.LEGAL.getCode() + "_")) {
                    legalPartyTypeList.add(partySubclassType.replace(PartyTypeEnum.LEGAL.getCode() + "_", ""));
                }
            }
            caseDto.setLegalPartyTypeList(legalPartyTypeList);
        }
    }

    /**
     * 查询待督查任务列表(查询办案中的案件)
     *
     * @param: [queryDto]
     * @return: List<WaitingSupervisedTaskVo>
     * @Author: wuzhihui
     * @Date: 2022/12/01
     */
    @Override
    public List<WaitingSupervisedTaskVo> getWaitingSupervisedTaskList(WaitingSupervisedTaskQueryDto queryDto) {
        //查询区域直属机构
        if (CollectionUtils.isNotEmpty(queryDto.getAreaCodeList())) {
            MemberOrgRequest memberOrgRequest = new MemberOrgRequest();
            memberOrgRequest.setAreaCodeList(queryDto.getAreaCodeList());
            List<MemberOrg> memberList = memberOrgFeignApi.getMemberOrgByAreaCodeList(memberOrgRequest);
            List<String> orgCodeList = memberList.stream().map(MemberOrg::getXzzfOrgCode).collect(Collectors.toList());
            queryDto.setOrgCodeList(orgCodeList);
        }
        dealTaskDays(queryDto);
        PageHelper.startPage(queryDto.getPageNum(), queryDto.getLength());
        List<WaitingSupervisedTaskVo> result = caseMainInfoMapper.getWaitingSupervisedTask(queryDto);
        return result;
    }

    /**
     * 处理超期临期时间参数
     *
     * @param: [params]
     */
    public void dealTaskDays(WaitingSupervisedTaskQueryDto params) {
        if (StringUtils.isBlank(params.getDaysType())) {
            return;
        }
        //临期任务
        if (StringUtils.equals(YesOrNoEnum.NO.getCode(), params.getDaysType())) {
            params.setTaskEndTimeStartRange(Constant.TASK_TIME_RANGE_ZERO);
            switch (params.getTaskDays()) {
                case Constant.TASK_THIRTY_DAYS:
                    params.setTaskEndTimeStartRange(Constant.TASK_TIME_RANGE_THIRTY);
                    break;
                case Constant.TASK_TEN_TO_THIRTY_DAYS:
                    params.setTaskEndTimeStartRange(Constant.TASK_TIME_RANGE_TEN);
                    params.setTaskEndTimeEndRange(Constant.TASK_TIME_RANGE_THIRTY);
                    break;
                case Constant.TASK_ONE_TO_TEN_DAYS:
                    params.setTaskEndTimeEndRange(Constant.TASK_TIME_RANGE_TEN);
                    break;
            }
        } else {
            //超期任务
            switch (params.getTaskDays()) {
                case Constant.TASK_ALL_DAYS:
                    params.setTaskEndTimeEndRange(Constant.TASK_TIME_RANGE_MINUS_ONE);
                    break;
                case Constant.TASK_THIRTY_DAYS:
                    params.setTaskEndTimeEndRange(Constant.TASK_TIME_RANGE_MINUS_THIRTY);
                    break;
                case Constant.TASK_TEN_TO_THIRTY_DAYS:
                    params.setTaskEndTimeStartRange(Constant.TASK_TIME_RANGE_MINUS_THIRTY);
                    params.setTaskEndTimeEndRange(Constant.TASK_TIME_RANGE_MINUS_TEN);
                    break;
                case Constant.TASK_ONE_TO_TEN_DAYS:
                    params.setTaskEndTimeStartRange(Constant.TASK_TIME_RANGE_MINUS_TEN);
                    params.setTaskEndTimeEndRange(Constant.TASK_TIME_RANGE_MINUS_ONE);
                    break;
            }
        }
    }

    /**
     * 查询待督查任务信息(查询办案中的案件)
     *
     * @param: caseId
     * @return: List<WaitingSupervisedTaskVo>
     * @Author: wuzhihui
     * @Date: 2022/12/01
     */
    @Override
    public WaitingSupervisedTaskDetailVo getWaitingSupervisedTask(String caseId) {
        List<WaitingSupervisedTaskDetailVo> result = caseMainInfoMapper.getWaitingSupervisedTaskInfo(caseId);
        if (CollectionUtils.isNotEmpty(result)) {
            return result.get(0);
        }
        return null;
    }

    /**
     * 获取待督办需要通知浙政钉的用户id(办案人员+行政机关负责人)
     *
     * @param: [caseId]
     * @return: java.util.List<java.lang.String>
     * @Author: wuzhihui
     * @Date: 2022/12/02
     */
    @Override
    public HashSet<String> getWaitingSupervisedRelUserIdList(String caseId) {
        CaseMainInfo query = new CaseMainInfo();
        query.setId(caseId);
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectOne(query);
        if (caseMainInfo == null) {
            throw new BusinessException("该案件不存在!");
        }
        HashSet<String> userIdList = new HashSet<>();
        //查询办案人员
        List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
        List<String> handlerPersonUserIdList = caseHandlePersonRecordList.stream().map(CaseHandlePersonRecordVo::getHandlePersonId).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(handlerPersonUserIdList)) {
            userIdList.addAll(handlerPersonUserIdList);
        }
        //查行政机关负责人（因该角色人员过多暂时先不加）
        /*List<String> xzjgfzrUserIdList = caseMainInfoMapper.getXzjgfzrUserIdList(caseMainInfo.getCaseOrgCode());
        if (CollectionUtils.isNotEmpty(xzjgfzrUserIdList)) {
            userIdList.addAll(xzjgfzrUserIdList);
        }*/
        return userIdList;
    }

    /**
     * 获取关联案件列表
     *
     * @param queryNameDto 请求对象
     * @return 关联案件列表
     * @author lilihao
     * @date 2022/12/4 21:11
     */
    @Override
    public List<CaseInfoQueryVo> getRelCaseList(CaseInfoQueryNameDto queryNameDto) {
        //1.获取当前机构部门信息
        UserDTO userInfo = UserUtil.getUserInfo();
        String orgCode = userInfo.getOrgCode();

        //2.查询关联案件列表
        List<CaseInfoQueryVo> list = caseMainInfoMapper.getRelCaseList(orgCode, queryNameDto.getQueryName());
        list.forEach(a -> {
            a.getList().forEach(b -> {
                String partyId = b.getPartyId();
                if (StrUtil.isNotBlank(partyId)) {
                    b.setPartyName(casePartiesRecordService.getPartyNameByPartyIds(partyId));
                }
            });
        });
        return list;
    }

    /**
     * 描述：统一案件分页查询统计
     *
     * @author yehuafei
     * @date 2022-12-05
     */
    @Override
    public CaseInfoPageResponseStatistics getCaseInfoStatistics() {
        CaseInfoPageRequest caseInfoPageRequest = new CaseInfoPageRequest();
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            throw new RuntimeException("用户信息获取失败");
        }
        caseInfoPageRequest.setOrgCode(userInfo.getOrgCode());
        caseInfoPageRequest.checkOrgCode();
        List<CaseInfoPageResponseStatistics> statistics = caseMainInfoMapper.getCaseInfoStatistics(caseInfoPageRequest);
        CaseInfoPageResponseStatistics caseInfoPageResponseStatistics = new CaseInfoPageResponseStatistics();
        for (CaseInfoPageResponseStatistics statistic : statistics) {
            if (statistic.getDealCaseCount().equals(Constant.INTEGER_0)) {
                caseInfoPageResponseStatistics.setDealCaseCount(statistic.getEndCaseCount());
            } else {
                caseInfoPageResponseStatistics.setEndCaseCount(statistic.getEndCaseCount());
            }
        }
        return caseInfoPageResponseStatistics;
    }

    /**
     * 描述：统一案件颜色查询统计
     *
     * @author yehuafei
     * @date 2022-12-05
     */
    @Override
    public CaseInfoPageColorResponseStatistics getCaseInfoPageColorStatistics() {
        CaseInfoPageRequest caseInfoPageRequest = new CaseInfoPageRequest();
        UserDTO userInfo = UserUtil.getUserInfo();
        if (ObjectUtils.isEmpty(userInfo)) {
            throw new RuntimeException("用户信息获取失败");
        }
        caseInfoPageRequest.setOrgCode(userInfo.getOrgCode());
        caseInfoPageRequest.checkOrgCode();
        CaseInfoPageColorResponseStatistics colorStatistics = new CaseInfoPageColorResponseStatistics();
        colorStatistics.setRedNum(caseMainInfoMapper.getCaseInfoPageColorStatisticsRed(caseInfoPageRequest));
        colorStatistics.setYellowNum(caseMainInfoMapper.getCaseInfoPageColorStatisticsYellow(caseInfoPageRequest));
        colorStatistics.setBlueNum(caseMainInfoMapper.getCaseInfoPageColorStatisticsBlue(caseInfoPageRequest));
        colorStatistics.setTotal(colorStatistics.getRedNum() + colorStatistics.getYellowNum() + colorStatistics.getBlueNum());
        return colorStatistics;
    }


    /**
     * 获取案件信息
     *
     * @param searchDto 查询对象
     * @return 案件信息
     * @author lilihao
     * @date 2023/2/6 18:49
     */
    @Override
    public List<CaseMainInfo> getCaseInfo(CaseSearchDto searchDto) {
        PageHelper.startPage(1, 10);
        Example example = new Example(CaseMainInfo.class);
        if (StrUtil.isNotBlank(searchDto.getId())) {
            example.createCriteria().andEqualTo("id", searchDto.getId());
        }
        if (StrUtil.isNotBlank(searchDto.getNumber())) {
            example.createCriteria().andEqualTo("caseNumber", searchDto.getNumber());
        }

        if (StrUtil.isNotBlank(searchDto.getCaseName())) {
            example.createCriteria().andLike("caseName", searchDto.getCaseName() + "%");
        }

        if (StrUtil.isNotBlank(searchDto.getCaseActsCode())) {
            example.createCriteria().andEqualTo("caseActsCode", searchDto.getCaseActsCode());
        }
        return caseMainInfoMapper.selectByExample(example);
    }

    /**
     * 删除案件信息
     *
     * @param caseId 案件唯一标识
     * @return
     * @author lilihao
     * @date 2023/2/8 1:03
     */
    @Override
    public int delCaseInfo(String caseId) {
        return caseMainInfoMapper.deleteByPrimaryKey(caseId);
    }

    @Override
    public List<CaseDocumentCatalogChainInfoVo> getCaseDocumentCatalogChainInfosForApp(String caseId) {
        List<CaseDocumentCatalogChainInfoVo> caseSourceDocumentCatalogChainInfoVos = new ArrayList<>();
        List<CaseDocumentCatalogChainInfoVo> caseDocumentCatalogChainInfoVos = new ArrayList<>();
        //案件基础信息
        CaseMainInfoVo caseMainInfo = getCaseMainInfo(caseId);
        //案件案由、当事人类型
        String casePartiesReasonType = caseMainInfo.getCasePartiesReasonType();

        //1、组装预立案阶段
        //如果为案源案件 需展示案源相关文书
        if (ApiVisitDataSourceEnum.PUNISH_AY.getCode().equals(caseMainInfo.getDataSource())) {
            CaseDocumentCatalogChainInfoVo caseDocumentCatalogChainInfoVo = new CaseDocumentCatalogChainInfoVo();
            caseDocumentCatalogChainInfoVo.setStageName(Constant.CASE_SOURCE_STAGE_YLA);
            caseDocumentCatalogChainInfoVo.setStageCode(Constant.CASE_SOURCE_STAGE_CODE);
            caseDocumentCatalogChainInfoVo.setStageStatus(Constant.STRING_1);
            Example partyExample = new Example(CaseSourcePartyInfo.class);
            partyExample.createCriteria().andEqualTo("caseSourceId", caseMainInfo.getId()).andEqualTo("status", Constant.STRING_1);
            List<CaseSourcePartyInfo> caseSourcePartyInfos = caseSourcePartyInfoMapper.selectByExample(partyExample);
            //文书列表
            List<CaseDocumentCatalogChainDetailVo> caseDocumentCatalogChainDetailVos = new ArrayList<>();
            CaseSourceLinkRelateDocumentQueryDto query = new CaseSourceLinkRelateDocumentQueryDto();
            query.setCaseSourceId(caseMainInfo.getId());
            query.setDocumentRecordStatus(Constant.STRING_1);
            List<CaseStageLinkRelateDocumentVo> caseStageLinkRelateDocumentList = caseSourceDocumentRecordService.getCaseStageLinkRelateDocumentInfo(query);
            for (CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo : caseStageLinkRelateDocumentList) {
                caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                //多当事人
                if (caseSourcePartyInfos.size() > 1) {
                    String partyId = caseStageLinkRelateDocumentVo.getPartyId();
                    if (!ObjectUtils.isEmpty(partyId)) {
                        String[] partyIdArr = partyId.split(",");
                        if (partyIdArr.length == 1) {
                            CaseSourcePartyInfo caseSourcePartyInfo = caseSourcePartyInfoMapper.selectByPrimaryKey(partyId);
                            if (null != caseSourcePartyInfo) {
                                String documentKindName = caseStageLinkRelateDocumentVo.getDocumentKindName() + "(" + caseSourcePartyInfo.getPartyName() + ")";
                                caseStageLinkRelateDocumentVo.setDocumentKindName(documentKindName);
                            }
                        }
                    }
                }
                CaseDocumentCatalogChainDetailVo caseDocumentCatalogChainDetailVo = new CaseDocumentCatalogChainDetailVo();
                BeanUtils.copyProperties(caseStageLinkRelateDocumentVo, caseDocumentCatalogChainDetailVo);
                //关联附件
                CaseAttachmentInfoQueryDto attachmentInfoQueryDto = new CaseAttachmentInfoQueryDto();
                attachmentInfoQueryDto.setCaseId(caseId);
                attachmentInfoQueryDto.setDocumentCatalogCode(caseStageLinkRelateDocumentVo.getDocumentCatalogCode());
                attachmentInfoQueryDto.setPartyId(caseStageLinkRelateDocumentVo.getPartyId());
                List<CaseAttachmentInfoVo> caseAttachmentList = caseAppendixRecordService.getCaseAttachmentList(attachmentInfoQueryDto);
                List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
                caseAttachmentList.forEach(a -> {
                    DocumentRelateAttachmentVo vo = new DocumentRelateAttachmentVo();
                    BeanUtils.copyProperties(a, vo);
                    vo.setAttachmentId(a.getId());
                    vo.setAttachmentTitle(a.getAppendixName());
                    vo.setAttachmentUrl(a.getAppendixUrl());
                    vo.setAttachmentType(a.getAppendixType());
                    documentRelateAttachmentList.add(vo);
                });
                caseDocumentCatalogChainDetailVo.setDocumentRelateAttachmentList(documentRelateAttachmentList);

                caseDocumentCatalogChainDetailVos.add(caseDocumentCatalogChainDetailVo);
            }

            //案源附件查询
            List<CaseDocumentCatalogChainOfflineDetailVo> caseDocumentCatalogChainOfflineDetailVos = new ArrayList<>();
            Example materialExample = new Example(CaseSourceMaterialRecord.class);
            materialExample.createCriteria().andEqualTo("caseSourceId", caseId).andEqualTo("isDelete", Constant.STRING_0);
            List<CaseSourceMaterialRecord> caseSourceMaterialRecordList = caseSourceMaterialRecordMapper.selectByExample(materialExample);
            caseSourceMaterialRecordList.forEach(caseSourceMaterialRecord -> {
                CaseStageLinkRelateDocumentVo caseStageLinkRelateDocumentVo = new CaseStageLinkRelateDocumentVo();
                caseStageLinkRelateDocumentVo.setDocumentUrl(caseSourceMaterialRecord.getMaterialUrl());
                caseStageLinkRelateDocumentVo.setDocumentId(caseSourceMaterialRecord.getId());
                caseStageLinkRelateDocumentVo.setDocumentCreateTime(caseSourceMaterialRecord.getUploadTime());
                caseStageLinkRelateDocumentVo.setCreateUserName(caseSourceMaterialRecord.getUploadUserName());
                caseStageLinkRelateDocumentVo.setDocumentCatalogName(caseSourceMaterialRecord.getMaterialName());
                caseStageLinkRelateDocumentVo.setIsOnlyDetail(Constant.STRING_1);
                if (!ObjectUtils.isEmpty(caseSourceMaterialRecord.getEvidenceUid())) {
                    //证据文件
                    caseStageLinkRelateDocumentVo.setIsEvidenceDoc(YesOrNoEnum.YES.getCode());
                }
                CaseDocumentCatalogChainOfflineDetailVo caseDocumentCatalogChainOfflineDetailVo = new CaseDocumentCatalogChainOfflineDetailVo();
                BeanUtils.copyProperties(caseStageLinkRelateDocumentVo, caseDocumentCatalogChainOfflineDetailVo);
                caseDocumentCatalogChainOfflineDetailVo.setDocumentTittle(caseSourceMaterialRecord.getMaterialName());
                caseDocumentCatalogChainOfflineDetailVos.add(caseDocumentCatalogChainOfflineDetailVo);
            });
            Collections.sort(caseStageLinkRelateDocumentList, (o1, o2) -> o1.getDocumentCreateTime().compareTo(o2.getDocumentCreateTime()));
            caseDocumentCatalogChainInfoVo.setCaseDocumentCatalogChainDetailVoList(caseDocumentCatalogChainDetailVos);

            caseDocumentCatalogChainInfoVo.setDocumentOfflineDetailVoList(caseDocumentCatalogChainOfflineDetailVos);

            caseSourceDocumentCatalogChainInfoVos.add(caseDocumentCatalogChainInfoVo);
        }

        //案件阶段查询
        ConfigDictionaryInfoQueryDto dto = new ConfigDictionaryInfoQueryDto();
        dto.setIsEffective(Constant.STRING_1);
        dto.setDicFieldCode(Constant.STRING_CASE_STAGE);
        //案件处理-流程取remark为名称
        if (Constant.STRING_2.equals(caseMainDetailInfoMapper.getHandleConclusionByCaseId(caseId))) {
            dto.setIsRemarkName(Constant.WHETHER_STRING_YES);
        }
        List<ConfigDictionaryInfoVo> configDictionaryInfoVos = configDictionaryInfoService.getConfigDictionaryList(dto);
        configDictionaryInfoVos.forEach(e -> {
            CaseDocumentCatalogChainInfoVo catalogChainInfoVo = new CaseDocumentCatalogChainInfoVo();
            catalogChainInfoVo.setStageCode(e.getDicCode());
            catalogChainInfoVo.setStageName(e.getDicName());
            caseDocumentCatalogChainInfoVos.add(catalogChainInfoVo);
        });


        List<CaseDocumentCatalogChainDetailVo> caseDocumentCatalogChainDetailVoList = caseDocumentRecordService.doGetAllCaseDocumentInfoEffectiveByCaseId(caseId);
        caseDocumentCatalogChainDetailVoList.forEach(h -> {
            String documentKindCode = h.getDocumentKindCode();
            //非草稿状态的文书设置相关状态的名称
            if (!DocumentRecordStatusEnum.DRAFT.getCode().equals(h.getDocumentRecordStatus())) {
                h.setDocumentApprovalStatusName(DocumentStatusEnum.getValueByCode(h.getDocumentApprovalStatus()));

                h.setDocumentSentStatusName(DocumentStatusEnum.getValueByCode(h.getDocumentSentStatus()));
                h.setDocumentSignstampedStatusName(DocumentStatusEnum.getValueByCode(h.getDocumentSignstampedStatus()));
            }
            //送达回证不显示文书状态状态
            if (DocumentKindEnum.DOC_KIND_SDHZ.getCode().equals(documentKindCode)) {
                h.setDocumentSentStatusName(null);
                h.setDocumentSignstampedStatusName(null);
            }
            h.setDocumentRecordStatusName(DocumentRecordStatusEnum.getValueByCode(h.getDocumentRecordStatus()));

            if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(documentKindCode)) {
                h.setCaseDocumentTypeFlag(Constant.STRING_1);
            }
            // 强制执行显示执行情况
            if (DocumentKindEnum.DOC_KIND_QZZXSQS.getCode().equals(documentKindCode)) {
                h.setCaseDocumentTypeFlag(Constant.STRING_2);
            }
            //增加处罚决定书是否展示公示详情处理
            if (Constant.STRING_KIND_CODE_CFJDS.equals(documentKindCode)) {
                //默认展示公示详情按钮
                h.setIsShowPublicity(YesOrNoEnum.YES.getCode());
                h.setIsShowPublicityName("展示公示");
            }
            //文书地址逻辑
            if (StringUtils.isNotBlank(h.getDocumentAftersealUrl())) {
                h.setDocumentUrl(h.getDocumentAftersealUrl());
            }
            if (StringUtils.isNotBlank(h.getDocumentAfterSignUrl())) {
                h.setDocumentUrl(h.getDocumentAfterSignUrl());
            }
            String documentCatalogCode = h.getDocumentCatalogCode();
            AuditDetailDocumentQueryDto queryAttachment = new AuditDetailDocumentQueryDto();
            queryAttachment.setCaseId(caseId);
            queryAttachment.setDocumentCatalogCode(documentCatalogCode);
            queryAttachment.setPartyId(h.getPartyId());
            List<DocAttachmentsVo> attachmentsList = caseAppendixRecordService.getDocLinkAttachments(queryAttachment);
            List<DocumentRelateAttachmentVo> documentRelateAttachmentList = new ArrayList<>();
            attachmentsList.forEach(a -> {
                DocumentRelateAttachmentVo vo = new DocumentRelateAttachmentVo();
                BeanUtils.copyProperties(a, vo);
                vo.setAttachmentId(a.getId());
                vo.setAttachmentTitle(a.getAppendixName());
                vo.setAttachmentUrl(a.getAppendixUrl());
                documentRelateAttachmentList.add(vo);
            });
            h.setDocumentRelateAttachmentList(documentRelateAttachmentList);


            //多当事人案件中，文书中配置关联对象为当事人的，文书列表中标题中增加当事人名称展示。示例：电子送达地址确认书（张三）。
            String partyId = h.getPartyId();
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)
                    && DocumentLinkObjectTypeEnum.PERSON.getCode().equals(h.getDocumentLinkObjectType())
                    && (!ObjectUtils.isEmpty(partyId) && !partyId.contains(","))) {
                //多当事人合并处罚不拼接当事人名称
                //查询当事人名称
                List<CasePartiesRecordVo> casePartiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
                String partyName = "";
                for (CasePartiesRecordVo ele : casePartiesRecordList) {
                    String tmpPartyId = ele.getPartyId();
                    if (partyId.equals(tmpPartyId)) {
                        partyName = ele.getPartyName();
                        break;
                    }
                }
                h.setDocumentKindName(h.getDocumentKindName() + "(" + partyName + ")");
            }
        });

        //线下文书
        List<CaseDocumentCatalogChainOfflineDetailVo> documentOfflineDetailVoList = caseOfflineDocumentRecordService.doGetCaseDocumentCatalogChainOfflineDetailVo(caseId);
        String territoryCode = caseMainInfo.getCaseTerritoryCode();
        if (TerritoryCodeEnum.ZRZY.getCode().equals(territoryCode)) {
            //查询附件
            Example example = new Example(CaseAppendixRecord.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("appendixTypeId", AttachmentTypeEnum.ATTACHTYPE74.getCode()).andEqualTo("appendixStatus", Constant.STRING_1).andEqualTo("isDelete", Constant.STRING_0);
            List<CaseAppendixRecord> caseAppendixRecords = caseAppendixRecordMapper.selectByExample(example);
            if (!ObjectUtils.isEmpty(caseAppendixRecords)) {
                for (CaseAppendixRecord caseAppendixRecord : caseAppendixRecords) {
                    CaseDocumentCatalogChainOfflineDetailVo vo = new CaseDocumentCatalogChainOfflineDetailVo();
                    vo.setCaseStageCode(caseAppendixRecord.getCaseStageCode());
                    vo.setCaseStageName(caseAppendixRecord.getCaseStageName());
                    vo.setDocumentTittle(caseAppendixRecord.getAppendixName());
                    vo.setDocumentUrl(caseAppendixRecord.getAppendixUrl());
                    documentOfflineDetailVoList.add(vo);
                }
            }

        }
        caseDocumentCatalogChainInfoVos.forEach(h -> {
            List<CaseDocumentCatalogChainDetailVo> catalogChainDetailVos = new ArrayList<>();
            caseDocumentCatalogChainDetailVoList.forEach(g -> {
                if (h.getStageCode().equals(g.getCaseStageCode())) {
                    catalogChainDetailVos.add(g);
                }
            });
            List<CaseDocumentCatalogChainOfflineDetailVo> offlineDetailVos = new ArrayList<>();
            documentOfflineDetailVoList.forEach(i -> {
                if (h.getStageCode().equals(i.getCaseStageCode())) {
                    offlineDetailVos.add(i);
                }
            });
            h.setCaseDocumentCatalogChainDetailVoList(catalogChainDetailVos);
            h.setDocumentOfflineDetailVoList(offlineDetailVos);
        });

        for (int i = 0; i < caseDocumentCatalogChainInfoVos.size(); i++) {
            if (ObjectUtil.isNotEmpty(caseMainInfo.getCaseCurrentStageCode()) && caseMainInfo.getCaseCurrentStageCode().equals(caseDocumentCatalogChainInfoVos.get(i).getStageCode())) {
                if (i == caseDocumentCatalogChainInfoVos.size() - 1) {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("1");
                } else {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("2");
                }
            } else {
                if (caseDocumentCatalogChainInfoVos.get(i).getCaseDocumentCatalogChainDetailVoList().size() <= 0) {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("3");
                } else {
                    caseDocumentCatalogChainInfoVos.get(i).setStageStatus("1");
                }
            }
        }

        caseSourceDocumentCatalogChainInfoVos.addAll(caseDocumentCatalogChainInfoVos);
        return caseSourceDocumentCatalogChainInfoVos;
    }


/** ===================================== 查询 START ================================================ */

    /**
     * 【V1.11.1】描述： 工作台--待办任务
     *
     * @author: tianrunjia
     * @date: 2023-03-06
     **/
    //读库注解
    //@DS("punishRead")
    @Override
    public List<UniQueryWorkTaskVo> getWorkWaitTaskList(UniQueryDto uniQueryDto) {
        if (uniQueryDto.getLength() > 100) {
            throw new BusinessException("每页条数不能超过100");
        }
        PageHelper.startPage(uniQueryDto.getPageNum(), uniQueryDto.getLength());

        List<UniQueryWorkTaskVo> uniQueryWorkTaskVoList = caseMainInfoMapper.selectWorkWaitTaskList(uniQueryDto);
        uniQueryWorkTaskVoList.forEach(e -> {
            e.setCaseType(CaseTypeEnum.getValueByCode(e.getCaseType()));

            if (!ObjectUtils.isEmpty(e.getCaseTimeLimit()) && e.getCaseVerdictEndTime() == null
                    && !CaseStatusEnum.END_CASE.getCode().equals(e.getCaseStatus())) {
                int timeLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), e.getCaseTimeLimit());
                //红（当前日期-办案期限<0)、黄(当前日期-办案期限<=7)、蓝色(当前日期-办案期限>7)
                e.setTimeLimit(timeLimit);
                String timeLimitStr = "";
                if (timeLimit > 0) {
                    timeLimitStr = "剩" + timeLimit + "天";
                } else if (timeLimit < 0) {
                    timeLimitStr = "超" + (-timeLimit) + "天";
                }
                e.setTimeLimitStr(timeLimitStr);
                /*if (timeLimit < Constant.INTEGER_0) {
                    e.setTimeColor("red");
                } else if (timeLimit <= Constant.INTEGER_7) {
                    e.setTimeColor("yellow");
                } else if (timeLimit > Constant.INTEGER_7) {
                    e.setTimeColor("blue");
                }*/
            }
        });
        return uniQueryWorkTaskVoList;
    }

    /**
     * 【V1.11.1】描述： 工作台--待办任务颜色
     *
     * @author: tianrunjia
     * @date: 2023-03-06
     **/
    //读库注解
    //@DS("punishRead")
    @Override
    public UniQueryWorkTaskColorsVo getWorkWaitTaskListColors(UniQueryDto uniQueryDto) {
        List<UniQueryWorkTaskColorsRetVo> uniQueryWorkTaskColorsRetVoList = caseMainInfoMapper.selectWorkWaitTaskListColors(uniQueryDto);
        UniQueryWorkTaskColorsVo uniQueryWorkTaskColorsVo = new UniQueryWorkTaskColorsVo();
        if (uniQueryWorkTaskColorsRetVoList.size() > 0) {
            uniQueryWorkTaskColorsRetVoList.forEach(e -> {
                if ("red".equals(e.getCaseTimeColor())) {
                    uniQueryWorkTaskColorsVo.setRedNum(e.getColorCount());
                } else if ("yellow".equals(e.getCaseTimeColor())) {
                    uniQueryWorkTaskColorsVo.setYellowNum(e.getColorCount());
                } else if ("blue".equals(e.getCaseTimeColor())) {
                    uniQueryWorkTaskColorsVo.setBlueNum(e.getColorCount());
                }
            });
        }

        if (ObjectUtils.isEmpty(uniQueryWorkTaskColorsVo.getRedNum())) {
            uniQueryWorkTaskColorsVo.setRedNum(0);
        }
        if (ObjectUtils.isEmpty(uniQueryWorkTaskColorsVo.getYellowNum())) {
            uniQueryWorkTaskColorsVo.setYellowNum(0);
        }
        if (ObjectUtils.isEmpty(uniQueryWorkTaskColorsVo.getBlueNum())) {
            uniQueryWorkTaskColorsVo.setBlueNum(0);
        }

        return uniQueryWorkTaskColorsVo;
    }


/** ===================================== 查询 END ================================================ */

    /**
     * 【V1.11.1】描述：获取当前阶段案件可操作文书信息
     *
     * @param caseId 用例id
     * @param isMobile
     * @return {@link CaseStageOperateDocumentVo }
     * @author shishengyao
     * @date 2023/03/09
     */
    @Override
    public CaseStageOperateDocumentVo getCaseStageOperateDocument(String caseId, String isMobile) {
        CaseMainInfoVo caseMainInfoVo = this.getCaseMainInfo(caseId);
        CaseStageOperateDocumentVo vo = new CaseStageOperateDocumentVo();
        CaseKeyInfoQueryDto queryOperateDoc = new CaseKeyInfoQueryDto();
        //查询审批表
        queryOperateDoc.setDocumentTypeName(DocumentTypeEnum.APPROVAL_TABLE.getCode());
        queryOperateDoc.setCaseMainInfo(caseMainInfoVo);
        vo.setCaseDetailOperateDocInfoVoList(getCouldBeOperateDocListCurrentStage(queryOperateDoc));
        //法律文书
        queryOperateDoc.setDocumentTypeName(DocumentTypeEnum.LAW_DOCUMENT.getCode());
        queryOperateDoc.setIsMobile(isMobile);
        vo.setCaseDetailOperateApprovalTableInfoVoList(getCouldBeOperateDocListCurrentStage(queryOperateDoc));
        return vo;
    }

    /**
     * 件主表时效颜色定时初始化
     *
     * @param
     * @return
     * @author liyafeng
     * @date 2023/4/12
     */
    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public void initCaseTimeColor() {
        List<String> sqlList = new ArrayList<>();
        //初始化颜色为空
        String initAllNullSql = "update   upcase.case_main_info set  case_time_color=''";
        //初始化red
        String initRedSql = "update   upcase.case_main_info set  case_time_color='red'  where case_timelimit is not null and case_status not in ('3','5','8','7','12','13','14') and case_verdict_end_time is null and cast(date_part('day', cast(case_timelimit as TIMESTAMP)- now()) as int) <0 ";
        //初始化yellow
        String initYellowSql = "update   upcase.case_main_info set  case_time_color='yellow'  where case_timelimit is not null and case_status not in ('3','5','8','7','12','13','14') and case_verdict_end_time is null and cast(date_part('day', cast(case_timelimit as TIMESTAMP)- now()) as int) <=7 and cast(date_part('day', cast(case_timelimit as TIMESTAMP)- now()) as int) >=0 ";
        //初始化bule
        String initBuleSql = "update   upcase.case_main_info set  case_time_color='blue'  where case_timelimit is not null and case_status not in ('3','5','8','7','12','13','14') and case_verdict_end_time is null and cast(date_part('day', cast(case_timelimit as TIMESTAMP)- now()) as int)>7 ";
        sqlList.add(initAllNullSql);
        sqlList.add(initRedSql);
        sqlList.add(initYellowSql);
        sqlList.add(initBuleSql);
        sqlList.forEach(updateSql -> {
            caseMainInfoMapper.executeUpdateSql(updateSql);
        });
    }

    /**
     * 添加数据
     *
     * @param busiParamId
     * @param caseMainInfo
     * @param caseId
     * @param documentTypeName
     * @param casePartiesReasonType
     * @param caseParties
     * @param isLateFee
     * @param configWorkFlowDocumentList
     * @param caseDetailOperateDocInfoVoList
     * @param roleIdList
     */
    @Override
    public void setData(String busiParamId, CaseMainInfoVo caseMainInfo, String caseId, String documentTypeName, String casePartiesReasonType, List<CasePartiesRecordVo> caseParties, String isLateFee, List<ConfigWorkFlowDocument> configWorkFlowDocumentList, List<CaseDetailOperateDocInfoVo> caseDetailOperateDocInfoVoList, List<String> roleIdList) {
        configWorkFlowDocumentList.forEach(e -> {
            boolean roleRight = false;
            if (roleIdList.contains(e.getOperateAuthRole())) {
                roleRight = true;
            }
            if (roleRight) {
                String documentLinkObjectType = e.getRelatedHolderType();
                String documentTypeId = e.getDocumentType();
                String documentCatalogCode = e.getDocumentCatalogCode();
                String documentKindCode = e.getDocumentKindCode();
                //关联文书不放在操作文书列表中
                if (YesOrNoEnum.NO.getCode().equals(e.getIsMatchDocument())) {
                    if (Constant.STRING_KIND_CODE_SDHZ.equals(documentKindCode)) {
                        return;
                    }
                    CaseDetailOperateDocInfoVo operateDocInfo = new CaseDetailOperateDocInfoVo();
                    operateDocInfo.setCaseId(caseId);
                    operateDocInfo.setDocumentCatalogCode(documentCatalogCode);
                    operateDocInfo.setDocumentKindCode(documentKindCode);
                    operateDocInfo.setDocumentKindName(e.getDocumentKindName());
                    MachDocumentInfoVo machDocumentInfoVo = getMachDocumentInfo(busiParamId, documentCatalogCode);
                    operateDocInfo.setMachDocumentInfoVo(machDocumentInfoVo);
                    //根据文书目录编码查询关联文书
                    List<String> allRelationDocCatalogCodeList = getALLRelationDocCatalogCodeList(caseMainInfo.getBusiParamId(), documentCatalogCode);
                    operateDocInfo.setAllRelationDocCatalogCodeList(allRelationDocCatalogCodeList);
                    //查看是否已经有生成对应的文书
                    CaseDocumentRecord caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, e.getDocumentCatalogCode());
                    //判断是否是撤回状态
                    if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
                        operateDocInfo.setDocumentId(caseDocumentRecord.getId());

                        String documentStatus = caseDocumentRecord.getDocumentRecordStatus();
                        if (DocumentRecordStatusEnum.WITHDRAW.getCode().equals(documentStatus)) {
                            caseDocumentRecord = null;
                        } else {
                            //有效的且已生成的文书
                            //组装 文书已经生成且待签字确认的关联当事人id列表
                            //根据案件id+文书种类编码查询文书记录
                            CaseDocumentRecordQueryDto queryDocument = new CaseDocumentRecordQueryDto();
                            queryDocument.setCaseId(caseId);
                            queryDocument.setDocumentKindCode(documentKindCode);
                            List<CaseDocumentRecordVo> documentRecordList = caseDocumentRecordService.getCaseDocumentRecordList(queryDocument);
                            List<String> docIsExistsAndWaitToSignRelatedPartyIdList = new ArrayList<>();
                            if (!ObjectUtils.isEmpty(documentRecordList) && documentRecordList.size() > 0) {
                                for (CaseDocumentRecordVo ele : documentRecordList) {
                                    String signStatus = ele.getDocumentSignstampedStatus();
                                    if (DocumentStatusEnum.WAIT_TO_CONFIRM.getCode().equals(signStatus)) {
                                        String partyIdInfo = ele.getPartyId();
                                        if (!ObjectUtils.isEmpty(partyIdInfo)) {
                                            if (partyIdInfo.indexOf(Constant.STRING_COMMA) > 0) {
                                                String[] arr = partyIdInfo.split(Constant.STRING_COMMA);
                                                docIsExistsAndWaitToSignRelatedPartyIdList.addAll(Arrays.asList(arr));
                                                break;
                                            } else {
                                                docIsExistsAndWaitToSignRelatedPartyIdList.add(partyIdInfo);
                                            }
                                        }
                                    }
                                }
                            }
                            operateDocInfo.setDocIsExistsAndWaitToSignRelatedPartyIdList(docIsExistsAndWaitToSignRelatedPartyIdList);
                        }
                    }
                    List<CasePartyRelateDocInfoVo> casePartiesKeyInfoVos = new ArrayList<>();
                    CasePartyRelateDocInfoVo casePartyRelateDocInfo;
                    for (CasePartiesRecordVo party : caseParties) {
                        casePartyRelateDocInfo = new CasePartyRelateDocInfoVo();
                        BeanUtils.copyProperties(party, casePartyRelateDocInfo);
                        casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.NO.getCode());
                        //查看该当事人是否已经添加该文书
                        Example queryCountExample = new Example(CaseDocumentRecord.class);
                        queryCountExample.createCriteria().andEqualTo("caseId", caseId)
                                .andEqualTo("documentCatalogCode", documentCatalogCode)
                                .andEqualTo("partyId", casePartyRelateDocInfo.getPartyId())
                                //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                                .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
                        int count = caseDocumentRecordMapper.selectCountByExample(queryCountExample);
                        if (count > 0) {
                            casePartyRelateDocInfo.setIsAddedThisDoc(YesOrNoEnum.YES.getCode());
                        }
                        casePartyRelateDocInfo.setIsAddedThisDocName(YesOrNoEnum
                                .getValueByCode(casePartyRelateDocInfo.getIsAddedThisDoc()));
                        casePartiesKeyInfoVos.add(casePartyRelateDocInfo);
                    }
                    operateDocInfo.setDocRelatePartiesList(casePartiesKeyInfoVos);
                    //判断是否是案件操作文书
                    boolean isCaseStatusChangeDoc = false;
                    if (CaseStatusChangeTypeEnum.isCaseChangeDocEnum(e.getDocumentKindCode())) {
                        isCaseStatusChangeDoc = true;
                        operateDocInfo.setCaseDocumentTypeFlag(Constant.STRING_1);
                    }
                    String handleType = caseMainInfo.getHandleType();
                    //陈述申辩复核意见书按钮控制处理
                    if (DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode().equals(documentKindCode)) {
                        //判断是否存在陈述申辩笔录
                        //没有陈述申辩笔录, 不显示陈述申辩复核意见书按钮
                        CaseDocumentRecordDto CSSBBLRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, DocumentKindEnum.DOC_KIND_DK2CSSBBL.getCode());
                        if (ObjectUtil.isEmpty(CSSBBLRecord)) {
                            return;
                        }
                    }
                    if (DocumentKindEnum.DOC_KIND_CLGZSPB.getCode().equals(documentKindCode) || DocumentKindEnum.DOC_KIND_CLJDSPB.getCode().equals(documentKindCode)) {
                        CaseDocumentRecordDto CSSBBLRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, documentKindCode);
                        if (ObjectUtil.isNotEmpty(CSSBBLRecord)) {
                            return;
                        }
                    }

                    //查封扣押决定书按钮处理
                    if (DocumentKindEnum.DOC_KIND_DK2CFKYJDS.getCode().equals(documentKindCode)) {
                        CaseDocumentRecordDto CFKYRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, documentKindCode);
                        if (ObjectUtil.isNotEmpty(CFKYRecord)) {
                            return;
                        }
                    }

                    //涉刑移送公安结案报告显示特殊处理
                    if (DocumentKindEnum.DOC_KIND_JABG.getCode().equals(documentKindCode)) {
                        if (!isShowCriminalTransferCaseEndOperateDoc(caseMainInfo)) {
                            return;
                        }
                    }

                    //责令改正情况复查记录控制处理
                    //当本案件或案源里的历史记录里至少有一条责令改正通知书时，显示文书“责令改正情况复查记录 ”
                    if (DocumentKindEnum.DOC_KIND_ZLGZQKFCJL.getCode().equals(documentKindCode)) {
                        boolean isAdd = false;
                        //查询责令改正文书
                        CaseDocumentRecordDto ZLGZRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, DocumentKindEnum.DOC_KIND_ZLGZTZS.getCode());
                        if (ObjectUtil.isNotEmpty(ZLGZRecord)) {
                            isAdd = true;
                        }
                        if (!isAdd) {
                            //查询责令改正线下文书
                            List<CaseOfflineDocumentRecord> caseOfflineDocumentInfoList = caseOfflineDocumentRecordService.getCaseOfflineDocumentRecordByKindCodes(caseId, Arrays.asList(DocumentKindEnum.DOC_KIND_ZLGZTZS.getCode()));
                            if (ObjectUtil.isNotEmpty(caseOfflineDocumentInfoList)) {
                                isAdd = true;
                            }
                        }
                        if (!isAdd) {
                            return;
                        }
                    }

                    //查询文书种类
                    List<ConfigBusiParamDocumentInfo> configList = configBusiParamDocumentInfoService.getDocumentConfigInfoByDocumentCatalogCode(caseId, caseMainInfo, documentCatalogCode);
                    String kindCode;
                    if (!ObjectUtils.isEmpty(configList)) {
                        kindCode = configList.get(Constant.INTEGER_0).getDocumentKindCode();
                    } else {
                        throw new BusinessException("未匹配文书种类编码信息-caseId:" + caseId + ",documentCatalogCode:" + documentCatalogCode);
                    }

                    //文书是否处在不可处理的状态下（审批中）
                    boolean docIsOutOfDealStatus = false;
                    if (!ObjectUtils.isEmpty(caseDocumentRecord)) {
                        String docStatus = caseDocumentRecord.getDocumentAuditStatus();
                        if ("pending".equals(docStatus)) {
                            docIsOutOfDealStatus = true;
                        }
                        if (Constant.STRING_KIND_CODE_XZCFCXSPB.equals(kindCode)
                                && DocumentStatusEnum.CHECK_END.getCode().equals(caseDocumentRecord.getDocumentApprovalStatus())) {
                            //审批通过, 待送达时不显示行政处罚撤销审批表
                            docIsOutOfDealStatus = true;
                        }
                    }

                    ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getConfigBusiParamDocumentInfoByBusiParamIdAndCode(busiParamId, operateDocInfo.getDocumentCatalogCode());
                    operateDocInfo.setIsNeedApproval(configBusiParamDocumentInfo.getIsApprove());
                    operateDocInfo.setDocumentLinkObjectType(configBusiParamDocumentInfo.getDocumentLinkObjectType());
                    if (DocumentTypeEnum.LAW_DOCUMENT.getCode().equals(documentTypeName)) {
                        //法律文书
                        //不在需要隐藏的法律文书列表当中
                        if (!OPERATE_HIDE_DOC_LIST.contains(kindCode)) {
                            if (HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                                    && PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                                //单案由多当事人分别处罚
                                //不在需要隐藏的文书列表当中(单案由多当事人分别处罚时需要隐藏的)
                                if (!MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.contains(documentKindCode)) {
                                    //判断是否为结案报告（需要特殊处理）
                                    if (Constant.STRING_KIND_CODE_JABG.equals(kindCode)) {
                                        //判断各个子流程都已进入到结案阶段
                                        if (checkIsAllSubFlowInAppointStage(caseId) && !docIsOutOfDealStatus) {
                                            caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                        }
                                    } else {
                                        if (!docIsOutOfDealStatus) {
                                            caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                        }
                                    }
                                }
                            } else {
                                //单当事人单案由、单当事人多案由、单案由多当事人合并处罚
                                if (!docIsOutOfDealStatus) {
                                    caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                }
                            }
                        }
                    } else {
                        //审批表
                        //判断是否为"可以改变案件状态"的法律文书
                        if (isCaseStatusChangeDoc) {
                            //判断是否是"中止xx审批表"
                            if (!CaseStatusChangeTypeEnum.SUSPEND.getDocumentKindCode().equals(documentKindCode)) {
                                //判断是否已经生成,未生成时，可以提供入口，已经生成过了，不再给入口
                                if (ObjectUtils.isEmpty(caseDocumentRecord) && !docIsOutOfDealStatus) {
                                    caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                }
                            } else {
                                caseDetailOperateDocInfoVoList.add(operateDocInfo);
                            }
                        } else {
                            if (HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                                    && PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType)) {
                                //不在需要隐藏的文书列表当中(单案由多当事人分别处罚时需要隐藏的)
                                if (!MULTIPLE_PARTIES_PART_PUNISH_HIDE_DOC_LIST.contains(documentKindCode) && !docIsOutOfDealStatus && !Constant.STRING_KIND_CODE_XZCFCXSPB.equals(kindCode)) {
                                    //单案由多当事人分别处罚
                                    caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                }
                            } else {
                                //单当事人单案由、单当事人多案由、单案由多当事人合并处罚
                                if (!docIsOutOfDealStatus) {
                                    //如果单位参数配置 配置了开启滞纳金  则不添加加处罚款审批表
                                    //剔除行政处罚撤销审批表
                                    //产品需求 多当事合并处罚允许操作行政处罚撤销审批表
                                    if (!(PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(casePartiesReasonType) && HandleTypeEnum.PART_PUNISH.getCode().equals(handleType) && Constant.STRING_KIND_CODE_XZCFCXSPB.equals(kindCode))
                                            && !(Constant.STRING_1.equals(isLateFee) && Constant.STRING_KIND_CODE_JCFKSPB.equals(kindCode))
                                            //陈述申辩复核意见书只生成一次, 判断是否已经生成,未生成时，可以提供入口，已经生成过了，不再给入口
                                            && !(ObjectUtil.isNotEmpty(caseDocumentRecord) && DocumentKindEnum.DOC_KIND_DK1CSSBFHYJS.getCode().equals(kindCode))) {

                                        if (Constant.STRING_KIND_CODE_XZCFCXSPB.equals(kindCode) && !Constant.STRING_1.equals(caseMainInfo.getAdditionalType())) {
                                            //没有《行政处罚决定书》或《行政不予行政处罚决定书》不显示撤销行政处罚审批表
                                            CaseDocumentRecordCommonQueryDto commonQueryDto = new CaseDocumentRecordCommonQueryDto();
                                            commonQueryDto.setCaseId(caseId);
                                            commonQueryDto.setIsPunishDocument(Constant.STRING_1);
                                            List<CaseDocumentRecordDetailVo> caseDocumentRecordDetailVoList = caseDocumentRecordService.getCaseDocumentRecordDocNumberInfoList(commonQueryDto);
                                            if (ObjectUtil.isNotEmpty(caseDocumentRecordDetailVoList)) {
                                                caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                            }
                                        } else {
                                            caseDetailOperateDocInfoVoList.add(operateDocInfo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
    }

    /**
     * 描述： 是否显示涉刑移送结案文书控制特殊处理
     *
     * @return
     * @author: zhengqiang
     * @date: 2023/6/27
     * @param: caseMainInfo
     **/
    private boolean isShowCriminalTransferCaseEndOperateDoc(CaseMainInfoVo caseMainInfo) {
        String caseId = caseMainInfo.getId();
        String caseCurrentStageCode = caseMainInfo.getCaseCurrentStageCode();
        String lineCode = caseMainInfo.getLineCode();

        //结案阶段不做特殊处理
        if (CaseStageEnum.CLOSE_ARCHIVING.getCode().equals(caseCurrentStageCode)) {
            return true;
        }
        //人社条线且处于调查取证阶段显示结案
        if (StrUtil.isNotEmpty(lineCode) && lineCode.startsWith(TerritoryCodeEnum.RLSB.getCode())
                && CaseStageEnum.INVESTIGATION.getCode().equals(caseCurrentStageCode)) {
            return true;
        }
        //当多事人分别处罚不显示结案报告
        if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(caseMainInfo.getCasePartiesReasonType())
                && HandleTypeEnum.PART_PUNISH.getCode().equals(caseMainInfo.getHandleType())) {
            return false;
        }
//        //判断是否有涉刑移送记录
        List<String> caseSuccessList = caseMainInfoMapper.selectCriminalTransferCaseSuccessList(caseId);
        if (ObjectUtil.isNotEmpty(caseSuccessList)) {
            return true;
        }
        return false;
    }

    /**
     * 【V1.12.1】描述： 查询简案快办立案登记列表
     *
     * @return {@link List< TaskVo>}
     * @author: zhengqiang
     * @date: 2023/8/24
     * @param: caseDto
     **/
    //读库注解
    @DS("punishRead")
    @Override
    public List<TaskVo> getFastCaseRegisterList(FastCaseQueryDto fastCaseDto) {
        UserDTO userDTO = UserUtil.getUserInfo();
        if (userDTO == null) {
            throw new BusinessException("未登录或登录信息已失效");
        }
        CaseQueryDto caseDto = new CaseQueryDto();
        BeanUtils.copyProperties(fastCaseDto, caseDto);
        //设置登录用户信息
        caseDto.setUserId(userDTO.getUserId().toString());
        caseDto.setOrgCode(userDTO.getOrgCode());
        caseDto.setWaitHandleFlag(Constant.INTEGER_0);
        //简案快办
        caseDto.setCaseType(CaseTypeEnum.FAST_PROCEDURE.getCode());
        //立案阶段
        caseDto.setCaseStage(CaseStageEnum.CASE_REGISTER.getDes());
        if (caseDto.getLength() > 1000) {
            throw new BusinessException("每页条数不能超过1000");
        }
        PageHelper.startPage(caseDto.getPageNum(), caseDto.getLength());
        //机构判断
        checkOrgCode(caseDto);
        List<TaskVo> list = caseMainInfoMapper.getStageCaseListNew(caseDto);
        if (list != null && list.size() > 0) {
            for (TaskVo vo : list) {
                String caseId = vo.getCaseId();
                String mainHandlePerson = StrUtil.nullToEmpty(vo.getMainHandlePerson());
                String helpHandlePerson = ObjectUtil.isNotEmpty(vo.getHelpHandlePerson()) ? "、" + vo.getHelpHandlePerson() : "";
                vo.setHandlePersonName(mainHandlePerson + helpHandlePerson);
                vo.setTimeColor("");
                //caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
                vo.setCaseTypeCode(vo.getCaseType());
                vo.setCaseType(CaseTypeEnum.getValueByCode(vo.getCaseType()));
                //如果是公司主体，返回公司信息
                if (StringUtils.isNotEmpty(vo.getPartyType()) && vo.getPartyType().equals(Constant.STRING_2)) {
                    CasePartiesLegalInfo legalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(vo.getPartyId());
                    vo.setLegalInfo(legalInfo);
                }
                if (StringUtils.isNotEmpty(vo.getPartyName()) && vo.getPartyName().contains(",")) {
                    vo.setPartyType("multitude");
                }
                // 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
                vo.setCaseStatus(CaseStatusEnum.getValueByCode(vo.getCaseStatus()));
                //表单步骤处理
                CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
                vo.setSimpleFormType(caseMainDetailInfo.getSimpleFormType());
                //简案快办按钮处理
                List<FastCaseButtonVo> fastCaseButtonList = new ArrayList<>();
                if ("立案".equals(vo.getCaseCurrentStageName()) || "处罚告知".equals(vo.getCaseCurrentStageName())) {
                    FastCaseButtonVo detail = new FastCaseButtonVo("detail", "详情");
                    fastCaseButtonList.add(detail);
                }
                FastCaseButtonVo handle = new FastCaseButtonVo("handle", "处理");
                FastCaseButtonVo delete = new FastCaseButtonVo("delete", "删除");
                fastCaseButtonList.add(handle);
                fastCaseButtonList.add(delete);
                vo.setFastCaseButtonList(fastCaseButtonList);
            }
        }
        return list;
    }

}

